Jump to content

Need Help Making PHP Calender (excluding sundays)


dauzy

Recommended Posts

Hello,

 

I've haven't been a member to this forum for more then 24 hours and I've already got some greatly appreciated help. But, now its the time again for me to ask for help.  I used this a resource...my code follows this technique rather closely with some modifications to include a dynamic background change.

 

http://video.about.com/php/How-to-Create-a-PHP-Calendar.htm

 

Scenario:

 

So, I need to make a PHP calendar....Easy enough right...but there one problem.

 

I'm able to make the a "full" calendar but I need to modify the calendar to skip sundays... This means that all Sundays are excluded when making setting table. data.

 

 

So... the calendar would look like this:

 

                            July

 

Monday Tuesday Wednesday Thursday Friday Saturday 

                 

                1            2            3          4        5

7              8            9            10        11        12

14            15          16          17        18        19

21            22          23          24        25        26

27            28          29          30        31

 

 

 

Heres the php code that takes care of making the calendar....

 

//Create a varible directory, which holds information that is taken from the scan() funtion.

$directory = scan();

//Variables for the day, month and year

$date = time ();

$day = date('d', $date);

$month = date('m', $date);

$year = date('Y', $date);

 

//Finds the first day of the month

$first_day = mktime(0,0,0,$month, 1, $year);

 

//Calculates the day of the week that the first day is on

$day_of_week = date('D', $first_day);

 

//Sets the the day to a numerical value... Sun = 0...Sat = 6

switch($day_of_week){

case "Sun": $blank = 0; break;

case "Mon": $blank = 1; break;

case "Tue": $blank = 2; break;

case "Wed": $blank = 3; break;

case "Thu": $blank = 4; break;

case "Fri": $blank = 5; break;

case "Sat": $blank = 6; break;

}

 

//Calculates the days in the month

$days_in_month = cal_days_in_month(0, $month, $year);

 

 

$day_count = 1;

 

//This while loop creates the blank spaces before the first day of the month.

while($blank > 0)

{

echo "<td></td>";

$blank = $blank-1;

$day_count++;

}

 

$day_num = 1;

 

//This while loop is used to create a table row and table ddta.

while($day_num <= $days_in_month)

{

//If the $day_num is included in $directory new table data with corresponded .jpg will be used.

if(in_array($day_num, $directory))

{

$event = "images/_calendar/July/calendar/".$day_num.".jpg";

echo '<td width="145px" height="145px" background="'.$event.'">'.$day_num.'</td>';

$day_num++;

$day_count++;

}

else

{

//If $day_num is not included in $directory new table data will be displayed with the default.jpg

echo '<td width="145px" height="145px" background="images/_calendar/July/calendar/default.jpg">'.$day_num.'</td>';

$day_num++;

$day_count++;

}

 

//This will ensure table row in the calendar will only have 7 days to it.

if($day_count > 7)

{

echo "</tr><tr>";

$day_count = 1;

}

}

 

//This will ensure table row in the calendar will only have 7 days to it.

while($day_count > 1 && $day_count <= 7)

{

echo "<td></td>";

$day_count++;

}

 

 

Thanks,

Dauzy

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.