Hi guys,
I am working on a monthly calendar list for exhibitions. Most of the exhibitions last longer than a month and my client wants each one to be listed for every month.
The table has fields for startdate and enddate and I have managed to make a list that shows the exhibit in correct start month and end month, but I am not able to make them show in the months between.
I would also like the list to have December on top and January at the end.
Can anyone help, please?
(I have put in a months array and tried to use it, but with no luck)
Here is the code so far:
//Select the events for this year
$sql = "SELECT title, text, startdate, enddate FROM exlist WHERE YEAR(startdate) = YEAR(NOW()) ORDER BY id DESC";
$sql_result = mysql_query($sql);
while ($row = mysql_fetch_array($sql_result)) {
//Put the rows into an array indexed by the month
$event_start = date("n", strtotime($row['startdate']));
$event_end = date("n", strtotime($row['enddate']));
$events[$event_start][] = $row;
$events2[$event_end][] = $row;
}
//Loop from 1 to 12 to print all 12 months of the year
for ($i = 1; $i <= 12; $i++) {
//Outputs "January 2010", "February 2010", etc
echo "<h3>" . date("F Y", gmmktime(0, 0, 0, ($i)+1, 0, gmdate('Y'))) . "</h3>";
$months = array( 1 => 'January', 2 => 'February', 3 => 'March', 4 => 'April',
5 => 'May', 6 => 'June', 7 => 'July', 8 => 'August',
9 => 'September', 10 => 'October', 11 => 'November',
12 => 'December');
//Now output the list of events
if (count($events[$i]) > 0 ) {
foreach ($events[$i] as $row) {
//Name of the event
echo "<p><b>" . $row['title'] . "</b><br />" . $row['text'] . "</p>";
}
}
if (count($events2[$i]) > 0 ) {
foreach ($events2[$i] as $row) {
//Name of the event
echo "<p><b>" . $row['title'] . "</b><br />" . $row['text'] . "</p>";
}
}
}
Thanks!