phpmyadmin中的以下查询返回三列(entry_id),其中包含三个不同的条目ID。
SELECT sub_1.entry_id, sub_2.entry_id, sub_3.entry_id
FROM exp_judging_portfolios AS jud
LEFT JOIN exp_submissions AS sub_1 ON sub_1.id = jud.rel_id_1
LEFT JOIN exp_submissions AS sub_2 ON sub_2.id = jud.rel_id_2
LEFT JOIN exp_submissions AS sub_3 ON sub_3.id = jud.rel_id_3
WHERE sub_1.member_group = $member_group
AND jud.pre = 1
GROUP BY jud.rel_id_1
然而,当我在页面中返回结果时,我得到一个只有一个条目id的单个数组。
以下是我用来生成结果的代码
$sql = "
SELECT sub_1.entry_id, sub_2.entry_id, sub_3.entry_id
FROM exp_judging_portfolios AS jud
LEFT JOIN exp_submissions AS sub_1 ON sub_1.id = jud.rel_id_1
LEFT JOIN exp_submissions AS sub_2 ON sub_2.id = jud.rel_id_2
LEFT JOIN exp_submissions AS sub_3 ON sub_3.id = jud.rel_id_3
WHERE sub_1.member_group = $member_group
AND jud.pre = 1
GROUP BY jud.rel_id_1
";
$query = $this->EE->db->query($sql);
$submissions_portfolio = $query->result_array();
print_r($submissions_portfolio);
这是什么回复:
Array ( [0] => 354 )
有谁知道为什么?如果是这样,如何返回所有3个入口ID?
答案 0 :(得分:1)
这次只得到一个结果的原因是因为所有3个选定的ID都具有相同的别名entry_id
。他们最终会互相覆盖。
您应尝试以不同方式命名:
SELECT sub_1.entry_id AS id_1, sub_2.entry_id AS id_2, sub_3.entry_id AS id_3