[英]How join two table or writing custom queries in Datatable php?
我正在使用數據表將數據列為服務器端腳本。
// 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;";
步驟1:打開ssp.class.php
步驟2:找到這行..... FROM'$ table'
步驟3:刪除單引號.... FROM $ table
步驟4:對其他人執行相同的操作..... FROM'$ table'
FROM $table"
步驟5:您現在可以將子查詢添加到$ table
示例$ table =“(從my_list連接中選擇* ...)”;
步驟6:慶祝=)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.