1

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?

10
  • Is 354 the last row? Probably it's not merging the array somewhere (in the result_array() method), so only the last result is shown in the array. Commented Oct 3, 2013 at 8:51
  • Yes, the last result. Any ideas on the fix? Commented Oct 3, 2013 at 8:53
  • Can you show us the result_array() method? Commented Oct 3, 2013 at 9:35
  • @davey Sorry, what do you mean by method? Commented Oct 3, 2013 at 9:38
  • You're calling a function here: $query->result_array(); can you show us this function? Commented Oct 3, 2013 at 10:00

1 Answer 1

1

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

Sign up to request clarification or add additional context in comments.

1 Comment

Thank you! That never even crossed my mind. Lesson learnt! (hopefully)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.