Jump to content

Need help debugging a calendar program I found on the web.


boom_roasted

Recommended Posts

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: messedupz.png

 

 

How can I get the $today's to turn into 1, 2, 3, 4?

<?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.

<?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!

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.