Hello. Here I am again with my calendar script. Im trying to make it as simple as possible but can get it to work properly. As it is below it doesnt show the dates correctly and the table doesnt break after 7 days. Any tips ?

<?php 
echo "<table border=1>"; 
echo "<tr><td colspan=7>".date("F Y")."</td></tr>"; 

$weekdays = array("Mon","Tue","Wed","Thu","Fri","Sat","Sun"); 
echo "<tr>"; 
foreach ($weekdays as $weekday) { 
 echo "<td>$weekday</td>"; 
} echo "</tr>"; 

echo "<tr>"; 
for ($dim=1; $dim<=date('t'); $dim++) { 
 $timestamp = strtotime(date("Y-m-".$dim)); 
 $day = date("w", $timestamp); 

if ($dim == date("d")) { 
 print "<td><b>$dim</b></td>"; 
} 
elseif ($day==0 or $day==6) { 
 echo "<td><font color=red>$dim</font></td>"; 
} 
else { 
 echo "<td>$dim</td>"; 
}} 
echo "</tr>"; 
echo "</table>"; 
?> 

    You would need to do a row break on each 6th day...

    <?php
    echo "<table border=1>";
    echo "<tr><td colspan=7>".date("F Y")."</td></tr>";
    
    $weekdays = array("Mon","Tue","Wed","Thu","Fri","Sat","Sun");
    echo "<tr>";
    foreach ($weekdays as $weekday) {
    echo "<td>$weekday</td>";
    } echo "</tr>";
    
    echo "<tr>";
    for ($dim=1; $dim<=date('t'); $dim++)
    {
    	$timestamp = strtotime(date("Y-m-".$dim));
    	$day = date("w", $timestamp);
    
    	if ($dim == date("d")) 
    	{
    		print "<td><b>$dim</b></td>";
    	}
    	else if ($day==0 or $day==6) 
    	{
    		echo "<td><font color=red>$dim</font></td>";
    		if ( $day == 6 )
    			echo "</tr><tr>";
    	}
    	else 
    	{
    		echo "<td>$dim</td>";
    	}
    }
    echo "</tr>";
    echo "</table>";
    ?>

    Only problem that is left is to offset the first day of the month to the corresponding day.

      Thanks for answer. I have now found another script and rewritten it to my needs. The only thing thats missing if to get it to hightlight the current date. Iv tried several things but failed. Any suggestions :

      <? 
      $month = date("m"); # Current month 
      $date  = date("d"); # Current date 
      $year  = date("Y"); # Current year 
      
      $num_days = date('t',mktime($hrs,$min,$sec,$month,$date,$year));# Number of days in month 
      $dim      = date('w',mktime($hrs,$min,$sec,$month,0,$year));    # Day in month 
      
      echo "<table border=1><tr>";                                    # Html table 
      echo "<tr><td colspan=7>".date('F Y')."</td></tr>"; 
      $days = array('Mon','Tue','Wed','Thu','Fri','Sat','Sun');       # Define weekdays 
      foreach($days as $day) {                                        # Loop through weekdays 
       echo "<td>".$day."</td>"; 
      } 
      echo "</tr>"; 
      
      $empty_cells = "<td></td>";             # Defines empty cells 
      for($i=1; $i<=$num_days; $i++) {        # Loops through the current month 
       echo $empty_cells."<td>$i</td>";       # Prints empty cells 
       $empty_cells=''; 
       $dim++; 
       if($dim==7) {          # Breakes table rows at 7 days 
        echo "</tr>";         # Ends Current month columns 
        $dim=0; 
       } 
      } 
      echo "</table>";        # End table 
      ?>

        Hello again.

        Now Im one step further🙂 I get the weekdays to correspond with the dates. But still cant get the table to start a new row when it comes to the end of the week. Any tips would really be apreciated.

        <? 
        $dates = date('t',mktime($hrs,$min,$sec,date('m'),date('d'),date('Y'))); # Days in current month 
        $week  = date('w',mktime($hrs,$min,$sec,date('m'),date('d'),date('Y'))); # Days in week 
        $wd    = array('Mon','Tue','Wed','Thu','Fri','Sat','Sun'); # Weekday names 
        
        echo "<table border=1>"; # Html table 
        
        echo "<tr>"; 
        foreach($wd as $w) { #Loops through weekday names 
        echo "<td>$w</td>"; 
        } 
        echo "</tr>"; 
        
        for($i=0; $i<date("w",mktime(0,0,0,date("m"),0)); $i++) { 
         echo "<td><!--Empty Cells--></td>"; # Checks for empty cells in table 
        } 
        
        for($i=1; $i<=$dates; $i++) { # Loops through dates 
        if($i==date('d')) { 
         echo "<td><b>$i</b></td>"; 
        } 
        else { 
         echo "<td>$i</td>";  # Prints all the days in the current month 
        } 
        } 
        echo "</tr>"; 
        echo "</table>"; 
        ?>
        
          Write a Reply...