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
https://forums.phpfreaks.com/topic/164475-solved-calendar-problem/
Share on other sites

add me : [email protected] 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 :)

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>

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.