Forum Moderators: open

Message Too Old, No Replies

selecting data from MySQL and grouping together

similar results

         

dgsk387

8:09 pm on Oct 19, 2007 (gmt 0)

10+ Year Member



I have a PHP page where it displays all the content from my DB.
field names: name, age, gender

Here is what it displays now:

Daniel Age:22 Gender: Male
Mike Age: 21 Gender: Male
Kristie Age: 22 Gender: Female
Mark Age: 25 Gender: Male
Leslie Age: 22 Gender: Female

What I want to do is group together the results that have the same Age. AND then I want to display a "Join Group" hyperlink to to the right of the FIRST result in each Group.

So I want the above to look like this instead:

Mike Age: 21 Gender: Male JOIN GROUP

Daniel Age:22 Gender: Male JOIN GROUP
Kristie Age: 22 Gender: Female
Leslie Age: 22 Gender: Female

Mark Age: 25 Gender: Male JOIN GROUP

Any ideas on how to accomplish this?

FourDegreez

11:38 pm on Oct 19, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Just order by the age column, and as you loop through the rows check if the age changes from the previous row.