Jump to content

turn list of events into a calendar layout


deansatch

Recommended Posts

I have this code which I use to list some events. But I have to make the list into a calendar instead now and still have the event dates clickable. I have been on for bloody ages trying to do this but can't figure out the best way to do it. The date is in the DB as a time() unix timestamp btw

 

	$query2 = mysql_query("SELECT * FROM dates WHERE id ='$id' ");
while($row2 = mysql_fetch_assoc($query2)){
	$date = $row2['date'];

echo '<p><a href="book.php?d='.$date.'&f='.$id.'">Book Now</a> for '.date("jS F Y",$date).'</p>';
}

 

Can anyone give me some pointers or suggest the best way to do this?

Here's one way of doing this -

 

1) Write or find a calendar script that accepts the year and month number as input values for the calendar month to display.

 

2) Retrieve the events from your database table that match the year and month number you are trying to display.

 

3) Loop over the events you just retrieved from your database table and store them in an array of arrays, where the main array index is the YYYY-MM-DD date the event occurs on. The array under each date allows for multiple events on any particular day.

 

4) In your calendar script, when you are looping over the days in the month, form the YYYY-MM-DD value for the current day and use that to test if there are any events on that date in the array you made in step #3. If there are, loop over and output the events as links in the calendar.

 

5) Done.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.