Page 1 of 1

Grouping Table Results Dynamicly

Posted: Tue Jun 17, 2003 2:18 pm
by romeo
I have a table with several fields that need to be displayed per record (there are thousands), the table has a "category" column with "data1" data2" "bob3" "imis4" and a dozen other things, is there a way (sql statement) that would grab each of the GROUP BY and display the CATAGORY name befor eit listed off the people in the catagory... i.e

catagory BOY
- Jim
- Farnk
- Sam
- Wally

category Grl
- Sue
- Beth

category DOG
- Ruger
- Fido


and so on and so forth?

Posted: Tue Jun 17, 2003 7:13 pm
by Paddy
Do you mean like this?

select * from table where category = 'boy';

Posted: Wed Jun 18, 2003 1:57 pm
by romeo
No, at least I dont think so...

I want a generic pull that displays all the data but groups it and before it displays a certain group, it displays what the group is

better?

Posted: Wed Jun 18, 2003 9:59 pm
by McGruff
ORDER BY category, name ( - or whatever col Jim, Beth & Fido are in)

As you loop through the result with mysql_fetch_array or whatever, store the current category in a $var.

In each new loop, check $result['category'] against $var: if they are different, echo $result['category'] . '<br />'; and reset $var = $result['category'].

If they are the same, do nothing.

Initialise $var = ''; before the while loop.