problem with calendar coding

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
namikun
Forum Newbie
Posts: 6
Joined: Sun Nov 06, 2011 9:14 am

problem with calendar coding

Post by namikun »

I tried to create calendar php code.the question is why the code cant run well? hope u all can help me:)
This is the code:

<html>
<head>
</head>

<body>
<?php if (isset($_GET['day']))
{
$day = $_GET['day'];
}
else
{
$day = date("j");
}
if (isset($_GET['month']))
{
$month = $_GET['month'];
}
else
{
$month = date("n");
}
if (isset($_GET['year']))
{
$year = $_GET['year'];
}
else
{
$year = date("Y");
}

// echo $day."/".$month."/".$year;


//calendar variable
$currentTimeStamp = strtotime("$year-$month-$day");
$monthName = date("F", $currentTimeStamp);
$numDays = date("t", $currentTimeStamp);
$counter =0;
?>

<table border='1'>
<tr>
<td><input style='width:50px;' type='button' value='<' name='previousbutton'</td>
<td colspan='5'><?php echo $monthName.", ".$year; ?></td>
<td><input style='width:50px;' type='button' value='>' name='nextbutton'</td>
</tr>

<tr>
<td width='50px'>Sun</td>
<td width='50px'>Mon</td>
<td width='50px'>Tue</td>
<td width='50px'>Wed</td>
<td width='50px'>Thu</td>
<td width='50px'>Fri</td>
<td width='50px'>Sat</td>
</tr>

<?php
echo "<tr>";

for($i = 1; $i < $numDays+1; $i++, $counter++)
{
$timeStamp = strtotime("$year-$month-$i");
if($i == 1)
{
$firstDay = date("w", $timeStamp);
for($j = 0; $j < $firstDay; $j++, $counter++)
{
//blank space
echo "<td>&nbsp;</td>";
}
}
if ($counter % 7 == 0)
{
echo "</tr><tr>";
//echo"<td align='center'>".$i"</td>";
}
}

echo "</tr>";


?>
</table>

</body>
</html>
internet-solution
Forum Contributor
Posts: 220
Joined: Thu May 27, 2010 6:27 am
Location: UK

Re: problem with calendar coding

Post by internet-solution »

What do you mean by -
namikun wrote: why the code cant run well?
What is not working? Are you getting any error messages?
Post Reply