display group_by results - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20) +--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23) +--- Thread: display group_by results (/showthread.php?tid=11740) |
display group_by results - El Forum - 09-22-2008 [eluser]Circus-Killer[/eluser] Hi there, I am executing a SELECT statement which uses a GROUP BY clause. How do I print out the results in their grouped formats. Example: -Group 1- value value value -Group 2- value value value display group_by results - El Forum - 09-22-2008 [eluser]xwero[/eluser] The group by in the statement compacts the group to one line so the result you get will be the last row that is fetched from the database. table: Code: number name Code: number name You need to query the database twice, first to get the group data and then to get the group item data. You can do it in one query if the group data is in each group item row using ORDER BY. But then your resultset can be significantly bigger and you have to do the grouping in php. |