Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6
  1. #1
    Regular Coder
    Join Date
    May 2007
    Location
    Indonesia
    Posts
    164
    Thanks
    10
    Thanked 0 Times in 0 Posts

    Php help with calendar

    Need help with this php script for calendar. I need the Saturday and Sunday background color to be different from the rest of the calendar. The calendar uses a stylesheet to help in display. Where should I put the class code within the php? Help much appreciated.

    PHP Code:
    <?php
    function showCalendar(){
        
    // Get key day informations. 
        // We need the first and last day of the month and the actual day
        
    $today    getdate();
        
    $firstDay getdate(mktime(0,0,0,$today['mon'],1,$today['year']));
        
    $lastDay  getdate(mktime(0,0,0,$today['mon']+1,0,$today['year']));
        
        
        
    // Create a table with the necessary header informations
        
    echo '<table>';
        echo 
    '  <tr><th colspan="7">'.$today['month']." - ".$today['year']."</th></tr>";
        echo 
    '<tr class="days">';
        echo 
    '  <td>Mo</td><td>Tu</td><td>We</td><td>Th</td>';
        echo 
    '  <td>Fr</td><td>Sa</td><td>Su</td></tr>';
        
        
        
    // Display the first calendar row with correct positioning
        
    echo '<tr>';
        for(
    $i=1;$i<$firstDay['wday'];$i++){
            echo 
    '<td>&nbsp;</td>';
        }
        
    $actday 0;
        for(
    $i=$firstDay['wday'];$i<=7;$i++){
            
    $actday++;
            if (
    $actday == $today['mday']) {
                
    $class ' class="actday"';
            } else {
                
    $class '';
            }
            echo 
    "<td$class>$actday</td>";
        }
        echo 
    '</tr>';
        
        
    //Get how many complete weeks are in the actual month
        
    $fullWeeks floor(($lastDay['mday']-$actday)/7);
        
        for (
    $i=0;$i<$fullWeeks;$i++){
            echo 
    '<tr>';
            for (
    $j=0;$j<7;$j++){
                
    $actday++;
                if (
    $actday == $today['mday']) {
                    
    $class ' class="actday"';
                } else {
                    
    $class '';
                }
                echo 
    "<td$class>$actday</td>";
            }
            echo 
    '</tr>';
        }
        
        
    //Now display the rest of the month
        
    if ($actday $lastDay['mday']){
            echo 
    '<tr>';
            
            for (
    $i=0$i<7;$i++){
                
    $actday++;
                if (
    $actday == $today['mday']) {
                    
    $class ' class="actday"';
                } else {
                    
    $class '';
                }
                
                if (
    $actday <= $lastDay['mday']){
                    echo 
    "<td$class>$actday</td>";
                }
                else {
                    echo 
    '<td>&nbsp;</td>';
                }
            }
            
            
            echo 
    '</tr>';
        }
        
        echo 
    '</table>';
    }

    showCalendar();
    ?>

  • #2
    Supreme Master coder! abduraooft's Avatar
    Join Date
    Mar 2007
    Location
    N/A
    Posts
    14,852
    Thanks
    160
    Thanked 2,223 Times in 2,210 Posts
    Blog Entries
    1
    The Dream is not what you see in sleep; Dream is the thing which doesn't let you sleep. --(Dr. APJ. Abdul Kalam)

  • #3
    Regular Coder
    Join Date
    May 2007
    Location
    Indonesia
    Posts
    164
    Thanks
    10
    Thanked 0 Times in 0 Posts

    Nice tip

    Thanks for the tip question is where do I place the code that will change bgcolor for Saturday and Sunday within the php I have already?

  • #4
    Regular Coder PHP6's Avatar
    Join Date
    Aug 2008
    Location
    Czech Republic
    Posts
    238
    Thanks
    18
    Thanked 34 Times in 33 Posts
    Quote Originally Posted by rjkdonaldson View Post
    Thanks for the tip question is where do I place the code that will change bgcolor for Saturday and Sunday within the php I have already?
    I have added just these three lines:

    PHP Code:
    if (($i==6)or($i==7)) $class .= ' style="background-color:#FF0000"';
    if ((
    $j==5)or($j==6)) $class .= ' style="background-color:#FF0000"';
    if ((
    $i==5)or($i==6)) $class .= ' style="background-color:#FF0000"'
    PHP Code:
    <?php
    function showCalendar(){
        
    // Get key day informations. 
        // We need the first and last day of the month and the actual day
        
    $today    getdate();
        
    $firstDay getdate(mktime(0,0,0,$today['mon'],1,$today['year']));
        
    $lastDay  getdate(mktime(0,0,0,$today['mon']+1,0,$today['year']));
        
        
        
    // Create a table with the necessary header informations
        
    echo '<table>';
        echo 
    '  <tr><th colspan="7">'.$today['month']." - ".$today['year']."</th></tr>";
        echo 
    '<tr class="days">';
        echo 
    '  <td>Mo</td><td>Tu</td><td>We</td><td>Th</td>';
        echo 
    '  <td>Fr</td><td>Sa</td><td>Su</td></tr>';
        
        
        
    // Display the first calendar row with correct positioning
        
    echo '<tr>';
        for(
    $i=1;$i<$firstDay['wday'];$i++){
            echo 
    '<td>&nbsp;</td>';
        }
        
    $actday 0;
        for(
    $i=$firstDay['wday'];$i<=7;$i++){
            
    $actday++;
            if (
    $actday == $today['mday']) {
                
    $class ' class="actday"';
            } else {
                
    $class '';
            }
            if ((
    $i==6)or($i==7)) $class .= ' style="background-color:#FF0000"';
            echo 
    "<td$class>$actday</td>";
        }
        echo 
    '</tr>';
        
        
    //Get how many complete weeks are in the actual month
        
    $fullWeeks floor(($lastDay['mday']-$actday)/7);
        
        for (
    $i=0;$i<$fullWeeks;$i++){
            echo 
    '<tr>';
            for (
    $j=0;$j<7;$j++){
                
    $actday++;
                if (
    $actday == $today['mday']) {
                    
    $class ' class="actday"';
                } else {
                    
    $class '';
                }
                if ((
    $j==5)or($j==6)) $class .= ' style="background-color:#FF0000"';
                echo 
    "<td$class>$actday</td>";
            }
            echo 
    '</tr>';
        }
        
        
    //Now display the rest of the month
        
    if ($actday $lastDay['mday']){
            echo 
    '<tr >';
            
            for (
    $i=0$i<7;$i++){
                
    $actday++;
                if (
    $actday == $today['mday']) {
                    
    $class ' class="actday"';
                } else {
                    
    $class '';
                }
                if ((
    $i==5)or($i==6)) $class .= ' style="background-color:#FF0000"';
                if (
    $actday <= $lastDay['mday']){
                    echo 
    "<td$class>$actday</td>";
                }
                else {
                    echo 
    '<td>&nbsp;</td>';
                }
            }
            
            
            echo 
    '</tr>';
        }
        
        echo 
    '</table>';
    }

    showCalendar();
    ?>

  • #5
    Regular Coder
    Join Date
    May 2007
    Location
    Indonesia
    Posts
    164
    Thanks
    10
    Thanked 0 Times in 0 Posts
    K dude will give it a go...have not tried it yet. Thanks.

  • #6
    Regular Coder
    Join Date
    May 2007
    Location
    Indonesia
    Posts
    164
    Thanks
    10
    Thanked 0 Times in 0 Posts

    Adding events (tooltip style)

    That worked thanks heaps! Now was wondering how I could add events (tooltip style) to the calendar. Even though adding events as a separate php file is an option adding events using tooltips is preferred.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •