sql - Select result in grouped row using fetch and while in PHP

Solution:
You have two options.
First, as you walk thru result, watch primary key and build second dimension (store rows in temporary array) until key changes. When it does, you have one logical row processed and stored in that temporary array. Something like this:
$last_id = null;
$result = array();
while (($row = fetch())) {
if ($row['id'] != $last_id) {
// do something with $result
$result = array();
$last_id = $row['id'];
}
$result[] = $row;
}
Second option is to perform two queries at once and retrieve data from both simultaneously. First query is grouped by primary key without left joins, second is select from previously left joined tables. Both queries must be sorted in the same way. You fetch one row from the first query and then fetch all queries with the same primary key from second query. Just the same way as merge sort works. It can help when you have big results, but usually you can stick with the first variant.
Share solution ↓
Additional Information:
Link To Answer People are also looking for solutions of the problem: failed to create image decoder with message 'unimplemented'
Didn't find the answer?
Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.
Similar questions
Find the answer in similar questions on our website.
Write quick answer
Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.