Coloring today and week-end in a calendar...

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
Peuplarchie
Forum Contributor
Posts: 148
Joined: Sat Feb 04, 2006 10:49 pm

Coloring today and week-end in a calendar...

Post by Peuplarchie »

Good day to you all,
I'm working on a calendar script.
I'm facing 2 questions;

1. How, if is this month, can I have the day in a different color ?
2. how could I have the Saturday and Sunday show in different color ?


Here is my code:

Code: Select all

 
 
<?
function showMonth($month, $year)
{
    $date = mktime(12, 0, 0, $month, 1, $year);
    $daysInMonth = date("t", $date);
    // calculate the position of the first day in the calendar (sunday = 1st column, etc)
    $offset = date("w", $date);
    $rows = 1;
 
    echo "<table border=\"1\" align=\"center\">\n";
    echo "<tr><td colspan=\"7\"><h1>" . date("F Y", $date) . "</h1></td></tr>";
    echo "<tr><th>Sunday</th><th>Monday</th><th>Tuesday</th><th>Wednesday</th><th>Thursday</th><th>Friday</th><th>Saturday</th></tr>";
    echo "\n\t<tr>";
    for($i = 1; $i <= $offset; $i++)
    {
        echo "<td></td>";
    }
    for($day = 1; $day <= $daysInMonth; $day++)
    {
        if( ($day + $offset - 1) % 7 == 0 && $day != 1)
        {
            echo "</tr>\n\t<tr>";
            $rows++;
        }
 
      echo "<td  valign=\"top\"><table border=\"0\" align=\"center\">";
    echo "<tr><td width=\"100\" valign=\"top\" bgcolor=\"cccc99\">" . $day . "</td></tr>";
    echo "<tr><td width=\"100\" height=\"100\" valign=\"top\"><br/></td></tr>";
    echo "</table></td>";
 
    }
    while( ($day + $offset) <= $rows * 7)
    {
        echo "<td></td>";
        $day++;
    }
    echo "</tr>\n";
    echo "</table>\n";
}
showmonth(12, 2008);
?>
 
 
 
Thanks !
User avatar
Peuplarchie
Forum Contributor
Posts: 148
Joined: Sat Feb 04, 2006 10:49 pm

Re: Coloring today and week-end in a calendar...

Post by Peuplarchie »

I foud it thanks you !

Code: Select all

 
 
if ($month == date("m") && $day == date("d")){
      echo "<td  valign=\"top\"><table border=\"0\" align=\"center\">";
    echo "<tr><td width=\"100\" valign=\"top\" bgcolor=\"999966\">" . $day . "</td></tr>";
    echo "<tr><td width=\"100\" height=\"100\" valign=\"top\"><br/></td></tr>";
    echo "</table></td>";
    
}else{
      echo "<td  valign=\"top\"><table border=\"0\" align=\"center\">";
    echo "<tr><td width=\"100\" valign=\"top\" bgcolor=\"cccc99\">" . $day . "</td></tr>";
    echo "<tr><td width=\"100\" height=\"100\" valign=\"top\"><br/></td></tr>";
    echo "</table></td>";
 
}
 
 
Am i doing it right ?
User avatar
papa
Forum Regular
Posts: 958
Joined: Wed Aug 27, 2008 3:36 am
Location: Sweden/Sthlm

Re: Coloring today and week-end in a calendar...

Post by papa »

if() {
$bgcolor = xxx
}
else {
$bgcolor = yyy
}

# echo "<td valign=\"top\"><table border=\"0\" align=\"center\">";
# echo "<tr><td width=\"100\" valign=\"top\" bgcolor=\"$bgcolor\">" . $day . "</td></tr>";
# echo "<tr><td width=\"100\" height=\"100\" valign=\"top\"><br/></td></tr>";
# echo "</table></td>";
Post Reply