Page 1 of 1

Queries

Posted: Sat Feb 11, 2006 10:27 am
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.

Posted: Sat Feb 11, 2006 10:40 am
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.

Posted: Sat Feb 11, 2006 10:49 am
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: