简体   繁体   中英

Single array where multiple should be returned

The following query in phpmyadmin returns three columns (entry_id) with three different entry ids as I need.

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

However, when I return the results in page, I get a single array with just one of the entry ids.

Here is the code I am using to generate the results

$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);   

Here is whats returned:

Array ( [0] => 354 ) 

Does anyone have any idea why? and if so, how to return all 3 entry ids?

The reason you only get one result this time, is because all 3 selected ids have the same alias entry_id . They end up overwriting each other.

You should try naming them differently:

SELECT sub_1.entry_id AS id_1, sub_2.entry_id AS id_2, sub_3.entry_id AS id_3

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM