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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.