Forum Moderators: coopster

Message Too Old, No Replies

PHP & MYSQL - Group by request

How to echo the name of the group.

         

tomda

8:44 am on Nov 17, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hi,

If my db is like this
NAME - CATEGORY
Ex1 - A
Ex2 - B
Ex3 - A
Ex4 - B

and I group the result by category, I get :
Ex1 Ex3 Ex2 Ex4

But I want this:
A - Ex1 Ex3
B - Ex2 Ex4

Is there a simple way to echo the name of the category before showing the grouped results?

Thanks

coopster

11:36 am on Nov 17, 2004 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Monitor for the group change in your processing loop and if it did indeed change, echo it to the browser.

tomda

1:05 pm on Nov 17, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



>> Monitor for the group change in your processing loop and if it did indeed change, echo it to the browser.

Thanks for your suggestion.

I knew I could do something like you said but I though that they would be an easy php function (may be with array) to check for group change.

// CHECK IF CATEGORIES MATCH
if ($record_previous!=$record["category"]) {
echo $record["category"];}

// WRITE THE NAME
echo $record["name"];

// SET A VARIABLE
$record_previous=$record["category"];