我使用datatables.net,但我努力工作,如何我可以嵌套查詢和聯接工作。我似乎找不到任何例子。我可以得到它顯示使用像這樣簡單的查詢(對於不同的表):Datatables - 嵌套的SELECT的和加入
// DB table to use
$table = 'support_msgs';
// Table's primary key
$primaryKey = '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' => 'id', 'dt' => 0),
array('db' => 'user_id', 'dt' => 1),
array('db' => 'title', 'dt' => 2),
array('db' => 'msg', 'dt' => 3),
array('db' => 'date', 'dt' => 4)
);
// SQL server connection information
$sql_details = array(
'user' => 'user',
'pass' => 'pass',
'db' => 'db',
'host' => 'localhost'
);
require('ssp.class.php');
// echo json_encode(
// SSP::simple($_GET, $sql_details, $table, $primaryKey, $columns)
//);
echo json_encode(
SSP::complex($_GET, $sql_details, $table, $primaryKey, $columns)
);
但現在,我有這個疑問,我看不到任何會指出我在正確的方向爲這:
SELECT
vp.id,
vp.post_title,
(
SELECT
vpm.meta_value
FROM
vhyky_postmeta vpm
WHERE vp.id = vpm.post_id
AND vpm.meta_key = 'cs_cause_goal_amount'
) AS Bonus,
(
SELECT
vpm.meta_value
FROM
vhyky_postmeta vpm
WHERE vp.id = vpm.post_id
AND vpm.meta_key = 'cs_cause_raised_amount'
) AS Deposit,
wt.name,
vp.post_content
FROM
vhyky_posts vp,
vhyky_postmeta vpm,
vhyky_term_relationships wtr,
vhyky_term_taxonomy wtt,
vhyky_terms wt
WHERE vp.post_type = 'cs_cause'
AND vp.post_status = 'publish'
AND vp.id = vpm.post_id
AND vp.id = wtr.object_id
AND wtr.term_taxonomy_id = wtt.term_taxonomy_id
AND wt.term_id = wtt.term_id
AND wtt.term_id = '114'
group by vp.id