Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Code to display results "grouped" by a certain field? 1

Status
Not open for further replies.

jpo245

Programmer
Jan 16, 2005
45
US
I have tables:
Users
UserSubscriptions
Mailing Lists.

I hope to display in a html table all the Mailing lists that each user subscribes to.
I would like a new header for each user, and with all the subcriptions listed below the header.

Does anyone know of the most efficient way to accomplish this?

I was thinking up some code that stores the "current" user of each record, and compares it to the previous record. If previous <> current, a new header will be inserted.

Does mysql/php have any built in code to make this easier?
Being a newbie, my code is inefficient enuff as it is.

Thanks!
 
Your thoughts are right - compare the user with the previous user, and if different, print a header.

There's no way to do this automatically, but in any event, the logic is quite simple:

for each record:
if user != prevuser, print header
set prevuser = user
print subscription details
 
life woudl suck without you tony..

million thanks again...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top