I was wondering if there was a simple way to create a two dimensional array from a mysql query.
I building an event calendar and thought the best way was to create a two dimensional array of all the events for each month and then as I build the calendar table check to see if the each day's date exists in the array then pull out the rest of the info on that date from the array.
At present I'm using:
while ($row = mysql_fetch_array($result)) {
$event_date = $row[event_date];
$events_array[$event_date][event_artist] = $row[artist];
$events_array[$event_date][event_venue] = $row[venue];
$events_array[$event_date][event_price] = $row[ticket_price];
}
to create the array
and
$cont = true;
if ($events_array) {
while ((list($date, $event_array) = each($events_array)) && ($cont)) {
if ($date == $link_date) {
$event_artist = $events_array[$date][event_artist];
$event_venue = $events_array[$date][event_venue];
$event_price = $events_array[$date][event_price];
echo "<br><span class=\"artist\">$event_artist</span>\n\t";
echo "<br><span class=\"event\">$event_venue</span>\n\t";
echo "<br><a href=\"#\">£ $event_price</a>\n\t";
$cont = false;
}
}
reset($events_array);
}
to add the info to each table cell.
Thanx
Tony