Forum Moderators: coopster
<?php
include 'config.php';
include 'opendb.php';
$eventquery = 'SELECT * FROM `Calendar Events` ORDER BY `event_date` , `event_enddate` ASC LIMIT 0 , 100';
$eventresult = mysql_query($eventquery);
$month = date("M");
$lastPrintedMonth="";
while($row = mysql_fetch_array($eventresult, MYSQL_ASSOC))
{
$converteddate = strtotime($row['event_date']);
$extractedmonth = $converteddate['mon'];
if($extractedmonth!=$lastPrintedMonth)
{
echo "<div id=\"dateheader\">$extractedmonth</div>";
$lastPrintedMonth=$extractedmonth;
}
echo "<div id=\"eventrow\"><div id=\"eventdate\"><strong>{$row['event_date']}</strong></div>" .
"<div id=\"eventtitle\"><img src=\"images/flag_{$row['event_flag']}.gif\" align=\"absmiddle\"/> " .
"{$row['event_name']}</div>" .
"<div id=\"eventlocation\">{$row['event_location']}</div>" .
"<div id=\"eventlink\"><a href=\"{$row['event_link']}\">Website »</a></div></div>" ;
}
?>
I would like it to extract the month and year from a date string in the format YYYY-MM-DD (stored in $row['event_date']) and create subheadings for each month and year. I had this working fine until I switched from a varchar to a date field, which was required because of expansion elsewhere in the site. As it stands, the script above does not work, and I was wondering if it were possible to modify it so it does, including headers for years. At the moment, the script ignores the months and just echoes a nice list of events.
Thanks,
Max
Cheers :)