Current location: Hot Scripts Forums » Programming Languages » PHP » Coloring today and week-end in a calendar...


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

Reply
  #1 (permalink)  
Old 12-02-08, 01:45 AM
peuplarchie's Avatar
peuplarchie peuplarchie is offline
Newbie Coder
 
Join Date: Nov 2008
Posts: 64
Thanks: 1
Thanked 0 Times in 0 Posts
Post Coloring today and week-end in a calendar...

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:
PHP Code:


<?
function showMonth($month$year)
{
    
$date mktime(1200$month1$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) % == && $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(122008);
?>
Thanks !
Reply With Quote
  #2 (permalink)  
Old 12-02-08, 02:33 AM
peuplarchie's Avatar
peuplarchie peuplarchie is offline
Newbie Coder
 
Join Date: Nov 2008
Posts: 64
Thanks: 1
Thanked 0 Times in 0 Posts
I foud it thanks you !
PHP Code:


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 ?
Reply With Quote
  #3 (permalink)  
Old 12-02-08, 05:43 AM
landing's Avatar
landing landing is offline
Coding Addict
 
Join Date: Jul 2006
Location: Scotland
Posts: 302
Thanks: 0
Thanked 0 Times in 0 Posts
Looks good to me.

For the weekend, perhaps...

PHP Code:

$dayIndex date("N"$date); // Get numerical day of the week from your date

if ($dayIndex == || $dayIndex == 7) {
     
// Then it's the weekend....

__________________
Always sanitise your data


Best regards
Reply With Quote
  #4 (permalink)  
Old 12-02-08, 05:47 AM
End User's Avatar
End User End User is offline
Level II Curmudgeon
 
Join Date: Dec 2004
Posts: 3,027
Thanks: 14
Thanked 35 Times in 33 Posts
Simpler......and you'd forgotten the '#' in front of the hex color.

PHP Code:

if ($month == date("m") && $day == date("d")){$BGCOLOR='#999966';}else{$BGCOLOR='#cccc99';}


      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>"
__________________
I don't live on the edge, but sometimes I go there to visit.
-------------------------------------------------------------------------
Sanitize Your Data | Oracle Date & Substring Functions | Code Snippet Library | [url=http://www.codmb.com/Call Of Duty[/url]
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump


All times are GMT -5. The time now is 08:24 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.