Jump to content

[SOLVED] Calendar Problem


twilitegxa

Recommended Posts

I can't figure out what I'm doing wrong in my code for this calendar. Upon running the script, I see the two pulldown menus for the month and year, and then I see the border for the table with the days of the week listed, but no values and above the table, three zeros are displayed for some reason. What is going on with my code? Here is the code for it:

 

<?php
define("ADAY", (60*60*24));
if (!checkdate($_POST[month], 1, $_POST[year]))
$nowArray = getdate();
$month = $nowArray['mon'];
$year = $nowArray['year'];
} else {
$month = $_POST[month];
$year = $_POST[year];
}
$start = mktime (12, 0, 0, $month, 1, $year);
$firstDayArray = getdate($start);
?>
<html>
<head>
<title><?php print "Calendar:
".$firstDayArray['month']." ".$firstDayArray['year'] ?></title>
</head>
<body>
<form method="post" action="<?php print "$_SERVER[php_SELF]"; ?>">
<select name="month">
<?php
$months = Array("January", "February", "March", "April", "May",
"June", "July", "August", "September", "October", "November", "December");

for ($x=1; $x <= count($months); $x++) {
print "\t<option value=\"$x\"";
print ($x == $month)?" SELECTED":"";
print ">".$month[$x-1]."\n";
}
?>
</select>
<select name="year">
<?php
for ($x=1980; $x<2010; $x++) {
print "\t<option";
print ($x == $year)?" SELECTED":"";
print ">$x\n";
}
?>
</select>
<input type="submit" value="Go!" />
</form>
<br />
<?php
$days = Array("Sunday", "Monday", "Tuesday", "Wednesday",
"Thursday", "Friday", "Saturday");

print "<TABLE BORDER="1" CELLPADDING="5">\n";
foreach ($days as $day) {
print "\t<td><b>$day</b></td>\n";
}
for ($count=0; $count < (6*7); $count++) {
$dayArray = getdate($start);
if (($count % 7) == 0) {
	if ($dayArray['mon'] != $month) {
		break;
	} else {
		print "</tr><tr>\n";
	}
}
if ($count < $firstDayArray['wday'] || $dayArray['mon'] != $month) {
	print "\t<td><br></td>\n";
} else {
	print "\t<td>".$dayArray['mday']."    </td>\n";
	$start += ADAY;
}
}
print "</tr></table>";
?>
</body>
</html>

Link to comment
Share on other sites

add me : RussellonMSN@hotmail.com I'll help for free.. Sorry for that unneeded extra info, I got reprimanded for 'advertising'.. the reason I want you to add me, is there is no demo of whats wrong, and its kinda hard to visualize this.. Anyway, add me or not its you call, however, maybe post some screenshots here :)

Link to comment
Share on other sites

I must have had some coding wrong, because I re-did my coding and now it is working. Here is the working code: :-)

 

<?php
define("ADAY", (60*60*24));
if (!checkdate($_POST['month'], 1, $_POST['year'])) {
$nowArray = getdate();
$month = $nowArray['mon'];
$year = $nowArray['year'];
} else {
$month = $_POST['month'];
$year = $_POST['year'];
}
$start = mktime (12, 0, 0, $month, 1, $year);
$firstDayArray = getdate($start);
?>
<html>
<head>
<title><?php print "Calendar:
".$firstDayArray['month']." ".$firstDayArray['year'] ?></title>
</head>
<body>
<form method="post" action="<?php print "$_SERVER[php_SELF]"; ?>">
<select name="month">
<?php
$months = Array("January", "February", "March", "April", "May",
"June", "July", "August", "September", "October", "November", "December");

for ($x=1; $x <= count($months); $x++) {
print "\t<option value=\"$x\"";
print ($x == $month)?" SELECTED":"";
print ">".$months[$x-1]."\n";
}
?>
</select>
<select name="year">
<?php
for ($x=1980; $x<2010; $x++) {
print "\t<option";
print ($x == $year)?" SELECTED":"";
print ">$x\n";
}
?>
</select>
<input type="submit" value="Go!" />
</form>
<br />
<?php
$days = Array("Sunday", "Monday", "Tuesday", "Wednesday",
"Thursday", "Friday", "Saturday");

print "<TABLE BORDER = 1 CELLPADDING=5>\n";
foreach ($days as $day) {
print "\t<td><b>$day</b></td>\n";
}
for ($count=0; $count < (6*7); $count++) {
$dayArray = getdate($start);
if (($count % 7) == 0) {
	if ($dayArray['mon'] != $month) {
		break;
	} else {
		print "</tr><tr>\n";
	}
}
if ($count < $firstDayArray['wday'] || $dayArray['mon'] != $month) {
	print "\t<td><br></td>\n";
} else {
	print "\t<td>".$dayArray['mday']."    </td>\n";
	$start += ADAY;
}
}
print "</tr></table>";
?>
</body>
</html>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.