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";
}

?>



    It looks liek you do not reset $addy[] for each day?
    Also, you could just use a foreach loop to echo the events.

      Thanks for your reply.

      Sorrt Im not sure what you mean, can you tell me where to put that in my code?

      Thankyou

        after $event_falls_on_day = false;
        add a line:

        $addy = array();

        This effectively empties your addy array, to start with a new list for a new day

          Thankyou very much.

          I think I need to store another value in this array too, can you tell me how I can modify my code to do this?

          Thankyou

            change:
            //add title to array here
            $addy[] = $event['title'];

            to:
            //add title to array here

                        $addy[] = array(
            'title'=>$event['title'],
            'date'=>$event['date']);
            

            and:

                for ($y = 1; $y <= count($addy); ++$y) {
                                        echo $addy[$y];
                    }

            to

            foreach($addy as $key => $value) 
              {
              echo $value['title'];
              echo $value['date'];
              }
            
              Write a Reply...