2016-01-13 51 views
0

我正在使用数据表列出数据作为服务器端脚本。如何在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服务器端脚本和工作非常好的单桌。

我想在列表行的同时连接两个表。但是我找不到加入表格或编写自定义查询的选项。

如果有可能,我该如何连接表格?

回答

0

这里有两个表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;"; 
0

步骤1:打开ssp.class.php

第2步:找到这行..... FROM '$表'

第3步:删除单引号.... FROM $表

第4步:做同样到另一个..... FROM '$表'“

         FROM $table" 

第5步:您现在可以添加子查询$表

例如$表= “(SELECT * FROM my_list加入...)”;步骤6:庆祝=)