Calendar days are off

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
xionhack
Forum Contributor
Posts: 100
Joined: Mon Nov 10, 2008 9:22 pm

Calendar days are off

Post by xionhack »

pickle | Please use [ code=php ], [ code=text ], etc tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: :arrow: Posting Code in the Forums to learn how to do it too.


Hello. I am working on a scheduler. On the month of January it's good. But when I move to other months, I see that there is a day in the first row that gets out of place. Can somebody help me?! Also, if it's possible, the calendar is starting with "Monday" right now. I want it to start with "Sunday". Here is the code for the calendar and for the css:

Code: Select all

 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "DTD/xhtml1-transitional.dtd">
<html>
<head>
   <link href="stylesheets/myschedule.css" rel="stylesheet" type="text/css" />
</head>
<body>
 
 <?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']));
    
     // get the current year
     $year = date("Y"); // year in full text 2008
    
     // get the current month
     $month = date("n");
    
    
     // 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>
     Monday
     </td>
     <td>
     Tuesday
     </td>
     <td>
     Wednesday
     </td>
     <td>
     Thursday
     </td>';
     echo '  <td>
     Friday
     </td>
     <td>
     Saturday
     </td>
     <td>
     Sunday
     </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>
        <div id=\"day_box\">
        <a href=\"myschedule_input.php?user={$_GET['user']}&date={$month}/{$actday}/{$year}\">
                $actday
        </a>" .
        show_schedule($month."/".$actday."/".$year) .
        "</div>
        </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>
            <div id=\"day_box\">
            <a href=\"myschedule_input.php?user={$_GET['user']}&date={$month}/{$actday}/{$year}\">
                $actday
            </a>" .
            show_schedule($month."/".$actday."/".$year) .
            "</div>
        
 
        </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>
            <div id=\"day_box\">
            <a href=\"myschedule_input.php?user={$_GET['user']}&date={$month}/{$actday}/{$year}\">
                $actday
            </a>" .
            show_schedule($month."/".$actday."/".$year) .
            "</div>
        </td>";;
             }
             else {
                 echo '<td>&nbsp;</td>';
             }
         }
        echo '</tr>';
     }
    
     echo '</table>';
 }
  
 showCalendar();
 ?>
 
CSS

Code: Select all

 
table {
   /*width:210px;*/
    border:0px solid #888;    
    border-collapse:collapse;
}
 
td {
    width:30px;
    border-collpase:collpase;
    border:1px solid #888;
    text-align:right;
    padding-right:5px;
}
 
.days{
    background-color: #F1F3F5;
}
 
th {
    border-collpase:collpase;
    border:1px solid #888;
    background-color: #E9ECEF;
}
 
.actday{
    background-color: #c22;
    font-weight:bold;
}
 
#day_box
{
    border:thick;
    border-color:#000;
    border-width:1;
    width:150px;
    height:100px;
}
 
#text_day
{
    font-size:10.5px;
    text-align:left;
}
 

pickle | Please use [ code=php ], [ code=text ], etc tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: :arrow: Posting Code in the Forums to learn how to do it too.
xionhack
Forum Contributor
Posts: 100
Joined: Mon Nov 10, 2008 9:22 pm

Re: Calendar days are off

Post by xionhack »

Nobody?!
Post Reply