I have a simple database with 3 columns: id, event_date, event_name
I have 9 rows in the database
id event_date event_name
1 2010-01-17 Food 17th
2 2010-01-17 Bar 17th
3 2010-01-17 Football 17th
4 2010-01-18 Food 18th
5 2010-01-18 Bar 18th
6 2010-01-18 Football 18th
7 2010-01-19 Food 19th
8 2010-01-19 Bar 19th
9 2010-01-19 Football 19th
I would like an output that looks like this
2010-01-17
Bar 17th
Food 17th
Football 17th
2010-01-18
Bar 18th
Food 18th
Football 18th
2010-01-17
Bar 19th
Food 19th
Football 19th
my code
<?php
$query = "SELECT DISTINCT event_date FROM events WHERE event_date >'$startdate' AND event_date <'$enddate'";
$result = mysql_query($query);
while($row = mysql_fetch_assoc($result))
{
echo "<b>". $row['event_date'] . "</b><br />";
$query2 = "SELECT event_name FROM events WHERE event_date >'$startdate' AND event_date <'$enddate' GROUP by event_name";
$result2 = mysql_query($query2);
while($row = mysql_fetch_assoc($result2))
{
echo $row['event_name'] . "<br />";
}
echo "<br />";
}
?>
unfortunately this gives me an output of
2010-01-17
bar open 17th
bar open 18th
bar open 19th
food 17th
food 18th
food 19th
football 17th
football 18th
football 19th
2010-01-18
bar open 17th
bar open 18th
bar open 19th
food 17th
food 18th
food 19th
football 17th
football 18th
football 19th
2010-01-19
bar open 17th
bar open 18th
bar open 19th
food 17th
food 18th
food 19th
football 17th
football 18th
football 19th
How can I group all by date, with only one date entry? Is this possible at all?
Many thanks