I'm a newbie to PHP could anyone help me with this please?
I am looping through an array of events and highlighting the apprpriate day of the month on bold. I would also like to list the events for that day.
The result of the code below is here:
http://www.w00t.biz/results.html
You can see that some of the titles are listed twice, when I only want them to belisted once.
Can anyone help?
Thankyou
<?php
//set event dates to array
$events['event1']['title'] = 'test event 1';
$events['event1']['startdate'] = mktime(0, 0, 0, 3, 5, 2006);
$events['event1']['enddate'] = mktime(0, 0, 0, 3, 8, 2006);
$events['event2']['title'] = 'test event 2';
$events['event2']['startdate'] = mktime(0, 0, 0, 3, 6, 2006);
$events['event2']['enddate'] = mktime(0, 0, 0, 3, 7, 2006);
$events['event3']['title'] = 'test event 3';
$events['event3']['startdate'] = mktime(0, 0, 0, 3, 22, 2006);
$events['event3']['enddate'] = mktime(0, 0, 0, 3, 26, 2006);
$events['event4']['title'] = 'test event 4';
$events['event4']['startdate'] = mktime(0, 0, 0, 3, 1, 2006);
$events['event4']['enddate'] = mktime(0, 0, 0, 3, 2, 2006);
for ($day = 1; $day <= 31; ++$day) {
$event_falls_on_day = false;
// check if an event falls on this day
foreach ($events as $event) {
// use date('j') since we dont need leading zeros
if (date('j', $event['startdate']) <= $day && date('j', $event['enddate']) >= $day) {
$event_falls_on_day = true;
//add title to array here
$addy[] = $event['title'];
}
}
// print day as bold if event falls on this day
if ($event_falls_on_day) {
echo '<b>' . $day .'</b>' ;
//diplay array titles here
for ($y = 1; $y <= count($addy); ++$y) {
echo $addy[$y];
}
} else {
echo $day;
}
echo "<br>\n";
}
?>