[英]How join two table or writing custom queries in Datatable php?
I am using datatable to list data as server side scripting. 我正在使用数据表将数据列为服务器端脚本。
// 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)
);
This is my php server side scripting and working very fine for single table. 这是我的php服务器端脚本,对于单个表工作得很好。
I want to join two table while listing table row. 我想在列出表行时加入两个表。 But I couldn't find any option for joining tables or writing custom queries.
但是我找不到用于连接表或编写自定义查询的任何选项。
how can I join table if it is possible? 如果有可能,我如何加入表格?
here two table keyid same field and other field fetch 这里两个表的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;";
Step 1: open ssp.class.php 步骤1:打开ssp.class.php
Step 2: locate this line..... FROM '$table' 步骤2:找到这行..... FROM'$ table'
Step 3: remove single quotation.... FROM $table 步骤3:删除单引号.... FROM $ table
Step 4: do the same to the other one ..... FROM '$table' " 步骤4:对其他人执行相同的操作..... FROM'$ table'
FROM $table"
Step 5: you can now add subquery to $table 步骤5:您现在可以将子查询添加到$ table
example $table="(select * from my_list join...)"; 示例$ table =“(从my_list连接中选择* ...)”;
Step 6: Celebrate =) 步骤6:庆祝=)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.