Queries

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Ree
Forum Regular
Posts: 592
Joined: Fri Jun 10, 2005 1:43 am
Location: LT

Queries

Post by Ree »

Say, I have events table in my db. All events have name, date and type. I need to present the data this way: a separate table is displayed for each date requested. In each table, all events for that particular date should be visible, grouped by their type. These groups must be separated in some way (doesn't matter in what way).

What do you think would be the best way to fetch and display the data in the view I described? Should I use a single resultset (includes all data for all requested days), or would it be better to use more resultsets (say, one for each date)? Should I use a multidimensional array ($events[$date][$type][$event]) to put the data from resultset(s) for easy HTML output?

Any ideas are welcome.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

Code: Select all

SELECT * FROM `table` WHERE `date` BETWEEN 'dateA' AND 'dateB' ORDER BY `date` ASC, `type` DESC
During output, you check if the date has changed, thus ending the greater table. When the type changes, you output a heading or some indicator it changed.
Ree
Forum Regular
Posts: 592
Joined: Fri Jun 10, 2005 1:43 am
Location: LT

Post by Ree »

Thanks feyd, the SQL you didn't need to write ;)

Why didn't I think of this??? It's really a very nice and elegant solution... and I've been thinking multidimensional arrays!! :oops:
Post Reply