• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
display group_by results

#1
[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

#2
[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
1       me
1       I
sql statement : SELECT * FROM users GROUP BY number, outputs
Code:
number  name
1       I

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.


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2020 MyBB Group.