Jump to content

Creating a PHP Calendar


hoopplaya4

Recommended Posts

Hey All,

 

I'm currently trying to create a PHP calendar.  Everything is going great so far, but I am having issues figuring out the logic for events that "wrap" or overflow to the next week below (for events that are multiple days). 

 

The basic structure of the code is using <DIVS>, each consisting of a day.  For example, <div id="day1">, <div id="day2">, etc...  Then, the displayed events are <DIVS> within the day <DIV>.

 

Here's the code showing the basic structure: (some parts have been removed to save space on this post):

 

 

 

<?php 

$events = mysql_query("SELECT * FROM event WHERE month = '$month' AND year = '$year' ORDER BY starttime");
    
function isMultiDay($event) {
        return $event['day'] != null && ($event['dayend'] - $event['day'] >= 1);
}

    while ( $event = mysql_fetch_array($events) )
    {
          $event_type_id = $event['event_type_id'];
          $event_type = mysql_query("SELECT * FROM event_type WHERE id = '$event_type_id'");
          $event_type = mysql_fetch_array($event_type);
          
	  //SET UP Database Entries in MM/DD/YY Format
	   $startDate = $event['month']."/".$event['day']."/".$event['year'];
           $endDate = $event['monthend']."/".$event['dayend']."/".$event['yearend'];
	   
if ( ($event['day'] == 1) && (!isMultiDay($event)) )  { $day[0] .= '<div id="event'.$event['id'].'" style="height:17px;"><div id=\'header'.$event['id'].'\'>'.$event['name'].'</div></div>';}

if ( ($event['day'] == 1) && (isMultiDay($event)) ) { $day[0] .= '<div id="event'.$event['id'].'" style="height:17px;"><div id=\'header'.$event['id'].'\' style="width:'.$dayLength.'%;>'.$event['name'].'</div></div>';}

if ( ($event['day'] == 2) && (!isMultiDay($event)) )  { $day[1] .= '<div id="event'.$event['id'].'" style="height:17px;"><div id=\'header'.$event['id'].'\'>'.$event['name'].'</div></div>';}

if ( ($event['day'] == 2) && (isMultiDay($event)) ) { $day[1] .= '<div id="event'.$event['id'].'" style="height:17px;"><div id=\'header'.$event['id'].'\' style="width:'.$dayLength.'%;>'.$event['name'].'</div></div>';}

if ( ($event['day'] == 3) && (!isMultiDay($event)) )  { $day[2] .= '<div id="event'.$event['id'].'" style="height:17px;"><div id=\'header'.$event['id'].'\'>'.$event['name'].'</div></div>';}

if ( ($event['day'] == 3) && (isMultiDay($event)) ) { $day[2] .= '<div id="event'.$event['id'].'" style="height:17px;"><div id=\'header'.$event['id'].'\' style="width:'.$dayLength.'%;>'.$event['name'].'</div></div>';}

	  //etc.....

 

Any ideas on how to help with events overflowing to the next week?  Maybe I'm doing this completely wrong, already?  Thanks!

Link to comment
https://forums.phpfreaks.com/topic/147209-creating-a-php-calendar/
Share on other sites

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.