Jump to content

php calendar


hedonomania
Go to solution Solved by Ch0cu3r,

Recommended Posts

There is sth wrong with my code. I am trying to program simple table that will display the days of the month. The internet explorer keeps on loading the page but without any output... Thanks in advance!
 

<?php
date_default_timezone_set ('Europe/Warsaw');
//11
print "Today is:<br/>";
print date ('jS F  Y l G:i a');
//14
?>
</head>
<body>

<?php
//20 creating date variables
$month=date('n');
$year=date('Y');
$day=date('j');

$previous_year=$year--;
$next_year=$year++;

$previous_month=$month--;
$next_month=$month++;
 

//32 what day of the week is the first day of the month
$first_day=mktime(0,0,0,$month,1,$year);
$day_of_week=date('D',$first_day);

print "<table border=1 width=358>";
print "<tr> $month $year </tr>";

print "<tr><td><td width=50>Monday</td>";
print "<td><td width=50>Tuesday</td>";
print "<td><td width=50>Wednesday</td>";
print "<td><td width=50>Thursday</td>";
print "<td><td width=50>Friday</td>";
print "<td><td width=50>Saturday</td>";
print "<td><td width=50>Sunday</td></tr>";

//blank days in calendar table
$day_of_week = date('D', $first_day);

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

//setting the day count at 1
$day_count=1;

print "<tr>";
//62 while loop to generate first blank days and than all days in the month
while ( $blank >0 ) {
 print "<td></td>";
 $blank=$blank-1;
 $day_count++;
 }
 

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

 

//77 while loop to generate the days of the month

 

while ($day_number<=$days_in_month) {
 print "<td> $day_number </td>";
 $day_number++;
 $day_count++;

 

//84 new week starting at new row
  if($day_count>7) {
  print "<tr></tr>";
  $day_count=1;
    }
    }

 

//91 blank days for not filled days at the end of month
while ( $day_count>1 AND $daycount<=7) {
 print "<td></td>";
 $day_count++;
     }

//96 end of the calendar table
print "</tr></table>";
   
?>
</body>
</html>

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.