As PaulF https://stackoverflow.com/a/31005385/3549014指出,你需要使用JOIN
或子查询从同一个表中检索父亲的名字。
我假设你正在使用ssp.class.php
根据您提到的示例在服务器端处理您的数据。
Class ssp.class.php
不支持连接和子查询,但有一个解决方法。技巧是使用子查询,如下所示$table
定义。代替table
与子查询中的实际表名。
$table = <<<EOT
(
SELECT
a.id,
a.name,
a.father_id,
b.name AS father_name
FROM table a
LEFT JOIN table b ON a.father_id = b.id
) temp
EOT;
$primaryKey = 'id';
$columns = array(
array( 'db' => 'id', 'dt' => 0 ),
array( 'db' => 'name', 'dt' => 1 ),
array( 'db' => 'father_id', 'dt' => 2 ),
array( 'db' => 'father_name', 'dt' => 3 )
);
$sql_details = array(
'user' => '',
'pass' => '',
'db' => '',
'host' => ''
);
require( 'ssp.class.php' );
echo json_encode(
SSP::simple( $_GET, $sql_details, $table, $primaryKey, $columns )
);
您还需要编辑ssp.class.php
并替换所有实例FROM `$table`
with FROM $table
删除反引号。
确保所有列名称都是唯一的,否则使用AS
分配别名。
NOTES
还有github.com/emran/ssp https://github.com/emran/ssp包含增强的存储库ssp.class.php
支持 JOIN。
LINKS
See jQuery DataTables:在 ssp.class.php 中使用 WHERE、JOIN 和 GROUP BY https://www.gyrocode.com/articles/jquery-datatables-using-where-join-and-group-by-with-ssp-class-php/了解更多信息。