Help with PHP Calendar code...
Posted on
16th Feb 2014 07:03 pm by
admin
Hello, I'm new to this forum and I'm glad I found it.
I wrote this code for a PHP calendar as an assignment for college.
It works fine, but I also want today's day to show in another color and I can't find how to do that.
Can anyone help?
Below is the code...
Code: <html>
<head>
<div align="center"> <h1>Calendar</h1> </div>
</head>
<body BGCOLOR="lightgreen">
<blockquote>
<p>
<div align="center">
<table border="1">
<?php
if (isset($_GET['next']))
{
$month = $_GET['month'] + 1 ;
$year= $_GET['year'];
if($month > 12)
{
$month = 1;
$year++ ;
}
$cur_date = mktime(0,0,0,$month,1,$year);
}
elseif(isset($_GET['prev']))
{
$month = $_GET['month'] - 1;
$year= $_GET['year'];
if($month < 1 )
{
$month = 12;
$year-- ;
}
$cur_date=mktime(0,0,0,$month,1,$year);
}
else
{
$cur_date=mktime();
$year=date('Y',$cur_date);
$month=date('m',$cur_date);
$cur_date = mktime(0,0,0,$month,1,$year);
}
$month_name = date('F', $cur_date);
$week_days = array(Mon,Tue,Wed,Thu,Fri,Sat,Sun);
echo "<tr><td colspan="7">$month_name $year</td></tr>";
echo '<tr>';
foreach($week_days as $day)
{
echo "<td>$day</td>";
}
echo '</tr>';
$num_of_days = date('t',$cur_date);
$i = 1;
$first_day = date('D', $cur_date);
while ($i <= $num_of_days)
{
echo '<tr>';
foreach($week_days as $day)
{
echo '<td>';
if ( (($i == 1) && ($day != $first_day)) || $i > $num_of_days)
$val = '';
else
$val = $i++;
echo "$val </td>";
}
echo '</tr>';
}
?>
</table>
</div>
</blockquote>
<div align="center">
<form name="nav_form" method="get" action = '<?php echo $_SERVER['PHP_SELF'];?>' >
<input type="submit" name="prev" value="<<" >
<input type="submit" name="next" value=">>" >
<input type="hidden" name="month" value='<?php echo $month?>' >
<input type="hidden" name="year" value='<?php echo $year ?>' >
</div>
</form>
</body>
</html>
No comments posted yet
Your Answer:
Login to answer
138
10
Other forums
How to show more than 1 users with this code...
Hello,
i have a table that shows users only if I, as Administrator, want to be shown. But its sho
Unidentified index error in a simple form
I have been trying to make an HTML form that is handled by a PHP script. So far my attempts to get i
Download Image from URL and Upload it
Ok, I have been googling for the last 1/2 hour trying to figure this out, Most likely I'm just not s
Help with parsing this html
Hi,
I've got some html i just need a couple of strings from.. argh, it's freaking me out. I've t
gather checkbox data from form into email
Hello all,
First, i'd like to thank everyone who responded to my previous posts regarding set
download directory onto C drive
I am attempting (if this is possible) to write a routine to automatically dump the contents of a dir
Pagination won't carry results past page 2.
Hi all,
I've worked out my pagination script and its paginating fine until I click next from
user validation always displaying invalid ? please help
Hello,
I have 2 accounts and there is a field in mysql called validated it can be either &quo
pagination - need help on passing of search query.
Hi, i have been trying for days but couldn't get this sorted out. Would like some professional help
What am I missing here? Help!
Hello all!. I can't seem to get this working right. Well - it renders right, but something is goin