gpt4 book ai didi

php - 如何在 Datatable php 中连接两个表或编写自定义查询?

转载 作者:行者123 更新时间:2023-11-29 21:37:54 24 4
gpt4 key购买 nike

我正在使用数据表将数据作为服务器端脚本列出。

    // DB table to use
$table = 'enquiry';

// Table's primary key
$primaryKey = 'enquiry_id';

// Array of database columns which should be read and sent back to DataTables.
// The `db` parameter represents the column name in the database, while the `dt`
// parameter represents the DataTables column identifier. In this case simple
// indexes
$columns = array(
array(
'db' => 'enquiry_date',
'dt' => 0,
'formatter' => function( $d, $row ) {
return date('jS M y', strtotime($d));
}
),
array('db' => 'parent_name', 'dt' => 1),
array('db' => 'child_name', 'dt' => 2),
array('db' => 'mobile', 'dt' => 3),
array('db' => 'emirate', 'dt' => 4),
array('db' => 'remarks', 'dt' => 5),
array('db' => 'enquiry_status_id', 'dt' => 6),
);

// SQL server connection information
$sql_details = array(
'user' => 'root',
'pass' => '',
'db' => 'lsn',
'host' => ''
);


/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* If you just want to use the basic configuration for DataTables with PHP
* server-side, there is no need to edit below this line.
*/

require( './server_side/scripts/ssp.class.php' );

echo json_encode(
SSP::simple($_GET, $sql_details, $table, $primaryKey, $columns)
);

这是我的 php 服务器端脚本,对于单个表来说工作得非常好。

我想在列出表行时连接两个表。但我找不到任何用于连接表或编写自定义查询的选项。

如果可能的话,如何加入表?

最佳答案

这里两个表keyid相同的字段和其他字段获取

$sql_t="SELECT tabkey.keyid, table1.value, table2.value
FROM
(SELECT table1.keyid FROM table1
UNION
SELECT table2.keyid FROM table2) as tabkey
LEFT JOIN
table1 on tabkey.keyid = table1.keyid
LEFT JOIN
table2 on tabkey.keyid = table2.keyid;";

关于php - 如何在 Datatable php 中连接两个表或编写自定义查询?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34766267/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com