twilitegxa Posted July 2, 2009 Share Posted July 2, 2009 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> Quote Link to comment https://forums.phpfreaks.com/topic/164475-solved-calendar-problem/ Share on other sites More sharing options...
RussellReal Posted July 2, 2009 Share Posted July 2, 2009 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 Quote Link to comment https://forums.phpfreaks.com/topic/164475-solved-calendar-problem/#findComment-867628 Share on other sites More sharing options...
twilitegxa Posted July 5, 2009 Author Share Posted July 5, 2009 Here is a screenshot of what the php outputs: Quote Link to comment https://forums.phpfreaks.com/topic/164475-solved-calendar-problem/#findComment-869017 Share on other sites More sharing options...
twilitegxa Posted July 5, 2009 Author Share Posted July 5, 2009 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> Quote Link to comment https://forums.phpfreaks.com/topic/164475-solved-calendar-problem/#findComment-869063 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.