boom_roasted Posted April 28, 2010 Share Posted April 28, 2010 When I use this code: <?php $now = getdate(); $monthStart = getdate(mktime(0, 0, 0, $now['mon'], 1, $now['year'])); $monthEnd = getdate(mktime(0, 0, 0, $now['mon'] + 1, 0, $now['year'])); ?> <html> <head> <title> My Calendar viewing <?php echo($now['month'] . ' ' . $now['year']); ?> </title> </head> <body> <table> <tr> <th colspan="7"> <?php echo($now['month'] . ' ' . $now['year']); ?> </th> </tr> <tr> <td> Monday </td> <td> Tuesday </td> <td> Wednesday </td> <td> Thursday </td> <td> Friday </td> <td> Saturday </td> <td> Sunday </td> </tr> <tr> <?php for($counter = 1; $counter < $monthStart['wday']; $counter++) { ?> <td> </td> <?php } $today = 0; for($counter = $monthStart['wday']; $counter <= 7; $counter++) { $today ++; ?> <td> $today </td> <?php } ?> </tr> <?php $totalWeeks = floor(($monthEnd['mday'] - $today) / 7); for($counter = 0; $counter < $totalWeeks; $counter++) { echo '<tr>'; for($i = 0; $i < 7; $i++) { $today ++; echo "<td>$today</td>"; } echo '</tr>'; } if($today < $monthEnd['mday']) { echo '<tr>'; for($i = 0; $i < 7; $i++) { $today++; if($today <= $monthEnd['mday']) { echo "<td>$today</td>"; } else { echo '<td> </td>'; } } echo '</tr>'; } ?> This is the result: How can I get the $today's to turn into 1, 2, 3, 4? Link to comment https://forums.phpfreaks.com/topic/200042-need-help-debugging-a-calendar-program-i-found-on-the-web/ Share on other sites More sharing options...
mattal999 Posted April 28, 2010 Share Posted April 28, 2010 <?php $now = getdate(); $monthStart = getdate(mktime(0, 0, 0, $now['mon'], 1, $now['year'])); $monthEnd = getdate(mktime(0, 0, 0, $now['mon'] + 1, 0, $now['year'])); ?> <html> <head> <title> My Calendar viewing <?php echo($now['month'] . ' ' . $now['year']); ?> </title> </head> <body> <table> <tr> <th colspan="7"> <?php echo($now['month'] . ' ' . $now['year']); ?> </th> </tr> <tr> <td> Monday </td> <td> Tuesday </td> <td> Wednesday </td> <td> Thursday </td> <td> Friday </td> <td> Saturday </td> <td> Sunday </td> </tr> <tr> <?php for($counter = 1; $counter < $monthStart['wday']; $counter++) { ?> <td> </td> <?php } $today = 0; for($counter = $monthStart['wday']; $counter <= 7; $counter++) { $today ++; ?> <td> <?php echo $today; ?> </td> <?php } ?> </tr> <?php $totalWeeks = floor(($monthEnd['mday'] - $today) / 7); for($counter = 0; $counter < $totalWeeks; $counter++) { echo '<tr>'; for($i = 0; $i < 7; $i++) { $today ++; echo "<td>$today</td>"; } echo '</tr>'; } if($today < $monthEnd['mday']) { echo '<tr>'; for($i = 0; $i < 7; $i++) { $today++; if($today <= $monthEnd['mday']) { echo "<td>$today</td>"; } else { echo '<td> </td>'; } } echo '</tr>'; } ?> Your $today wasn't wrapped in PHP tags, and therefore wasn't being parsed by PHP. Link to comment https://forums.phpfreaks.com/topic/200042-need-help-debugging-a-calendar-program-i-found-on-the-web/#findComment-1049942 Share on other sites More sharing options...
boom_roasted Posted April 28, 2010 Author Share Posted April 28, 2010 <?php $now = getdate(); $monthStart = getdate(mktime(0, 0, 0, $now['mon'], 1, $now['year'])); $monthEnd = getdate(mktime(0, 0, 0, $now['mon'] + 1, 0, $now['year'])); ?> <html> <head> <title> My Calendar viewing <?php echo($now['month'] . ' ' . $now['year']); ?> </title> </head> <body> <table> <tr> <th colspan="7"> <?php echo($now['month'] . ' ' . $now['year']); ?> </th> </tr> <tr> <td> Monday </td> <td> Tuesday </td> <td> Wednesday </td> <td> Thursday </td> <td> Friday </td> <td> Saturday </td> <td> Sunday </td> </tr> <tr> <?php for($counter = 1; $counter < $monthStart['wday']; $counter++) { ?> <td> </td> <?php } $today = 0; for($counter = $monthStart['wday']; $counter <= 7; $counter++) { $today ++; ?> <td> <?php echo $today; ?> </td> <?php } ?> </tr> <?php $totalWeeks = floor(($monthEnd['mday'] - $today) / 7); for($counter = 0; $counter < $totalWeeks; $counter++) { echo '<tr>'; for($i = 0; $i < 7; $i++) { $today ++; echo "<td>$today</td>"; } echo '</tr>'; } if($today < $monthEnd['mday']) { echo '<tr>'; for($i = 0; $i < 7; $i++) { $today++; if($today <= $monthEnd['mday']) { echo "<td>$today</td>"; } else { echo '<td> </td>'; } } echo '</tr>'; } ?> Your $today wasn't wrapped in PHP tags, and therefore wasn't being parsed by PHP. lol Silly me! Thanks for the help! Link to comment https://forums.phpfreaks.com/topic/200042-need-help-debugging-a-calendar-program-i-found-on-the-web/#findComment-1049950 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.