1. Home
  2. Computing & Technology
  3. PHP / MySQL

Simple PHP Calendar

By Angela Bradley, About.com

3 of 5

Headings and Blank Calendar Days

//Here we start building the table heads
echo "<table border=1 width=294>";
echo "<tr><th colspan=7> $title $year </th></tr>";
echo "<tr><td width=42>S</td><td width=42>M</td><td width=42>T</td><td width=42>W</td><td width=42>T</td><td width=42>F</td><td width=42>S</td></tr>";

//This counts the days in the week, up to 7
$day_count = 1;

echo "<tr>";
//first we take care of those blank days
while ( $blank > 0 )
{
echo "<td></td>";
$blank = $blank-1;
$day_count++;
}
The first part of this code very simply echos the table tags, the month name, and the headings for the days of the week. Then we start a while loop. What we are doing is echoing empty table details, one for each blank day we count down. Once the blank days are done it stops. At the same time, our $day_count is going up by 1 each time through the loop. This is to keep count so that we do not try to put more than seven days in a week.

[See working calendar example]

Explore PHP / MySQL
About.com Special Features

Stay connected and entertained with reviews on tips on the latest HDTVs, cellphones and more. More >

Easy ways to connect two computers for networking purposes. More >

  1. Home
  2. Computing & Technology
  3. PHP / MySQL
  4. Step By Steps
  5. PHP Calendar Example - PHP Sample Code - PHP Calendar Code

©2009 About.com, a part of The New York Times Company.

All rights reserved.