小编典典
正如PaulF所指出的,您需要使用JOIN或子查询从同一张表中检索父亲的名字。
我假设您是ssp.class.php根据您提到的示例在服务器端处理数据的。
类ssp.class.php不支持联接和子查询,但是有一种解决方法。诀窍是使用$table定义如下所示的子查询。table在子查询中替换为您的实际表名。
$table = <<
(
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`与FROM $table`删除反引号。
确保所有列名都是唯一的,否则用于AS分配别名。
笔记
还有github.com/emran/ssp存储库,其中包含增强的ssp.class.php支持JOIN。
链接
2020-05-17