sivarts Posted August 19, 2006 Share Posted August 19, 2006 Hi All-I've been racking my brains over this so I though I would show it to the experts. I am building a simple calendar but when I try and preview in my browser I get the following message:Fatal error: Maximum execution time of 60 seconds exceeded in C:\htdocs\MYSITE\MYFILE.php on line 147here's what is around line 147 (line 147 is just a } ) /* Generate the calendar body */ while ($currentDay <= $noDays) { if ($dayOfWeek == 7) { $dayOfWeek = 0; $calendar .= "</tr><tr>"; } $calendar .= "<td>$currentDay</td>"; [b] } // this is line 147[/b] $currentDay++; $dayOfWeek++; /* Filling in the end of the calendar body */ if ($dayOfWeek != 7) { $remainingDays = 7 - $dayOfWeek; $calendar .= "<td colspan='$remainingDays'> </td>"; } Can anyone tell my why I might be having this problem?? Here's the complete function: <?php function build_calendar($month,$year,$day) { /* Declaring the variables */ $daysOfWeek = array('Su','Mo','Tu','We','Th','Fr','Sa'); $firstDayOfMonth = mktime(0,0,0,$month,1,$year); $noDays = date('t',$firstDayOfMonth); $dateComponents = getdate($firstDayOfMonth); $dayOfWeek = $dateComponents['wday']; $monthName = date('F',mktime(0,0,0,$month,1,$year)); /* Computing the previous month. */ if($month == 1) { $mn=12; $yn=$year-1; } else { $mn=$month-1; $yn=$year; } /* Computing the next month. */ if($month == 12) { $mn2=1; $yn2=$year+1; } else { $mn2=$month+1; $yn2=$year; } /* Calendar header: next and previous month links */ $calendar = "<table>"; $calendar .= "<tr><td><a href=day.php?m=$mn&y=$yn&d=$day><</a></td>"; $calendar .="<td colspan=5 align=center>$monthName, $year</td>"; $calendar .="<td><a href=day.php?m=$mn2&y=$yn2&d=$day>></a></td></tr>"; $calendar .="<tr>"; /* Calendar header: Display the days of the week */ foreach($daysOfWeek as $day) { $calendar .= "<td>$day</td>"; } $calendar .= "</tr>"; $calendar .= "<tr>"; $currentDay = 1; /* Fill in the beginning of the calendar body */ if ($dayOfWeek > 0) { $calendar .= "<td colspan='$dayOfWeek'> </td>"; } /* Generate the calendar body */ while ($currentDay <= $noDays) { if ($dayOfWeek == 7) { $dayOfWeek = 0; $calendar .= "</tr><tr>"; } $calendar .= "<td>$currentDay</td>"; } $currentDay++; $dayOfWeek++; /* Filling in the end of the calendar body */ if ($dayOfWeek != 7) { $remainingDays = 7 - $dayOfWeek; $calendar .= "<td colspan='$remainingDays'> </td>"; } $calendar .= "</table>"; return $calendar;} if (isset($_GET['m']) && isset($_GET['y']) && isset($_GET['d'])){ $month = $_GET['m']; $year = $_GET['y']; $day = $_GET['d'];} else { $dateComponents = getdate(); $month = $dateComponents['mon']; $year = $dateComponents['year']; $day = $dateComponents['mday'];}echo build_calendar($month,$year,$day); ?>Any help would be GREATLY APPRECIATED. I'm a newbie so maybe there is something I am not aware of yet. Thanks! Quote Link to comment Share on other sites More sharing options...
Woolf Posted August 19, 2006 Share Posted August 19, 2006 Are you running this off of a shared host? If so, there may be a low execution time, and perhaps your script is taking too long to execute.Well, I just checked the script on my own server and it is indeed taking too long to load (over 60 seconds). Perhaps you should revise the script to make it so it will not take so long to load. Quote Link to comment Share on other sites More sharing options...
Woolf Posted August 19, 2006 Share Posted August 19, 2006 I did some debugging and the problem lies with your while loop.[code]<?phpwhile ($currentDay <= $noDays) { if ($dayOfWeek == 7) { $dayOfWeek = 0; $calendar .= "</tr><tr>"; } $calendar .= "<td>$currentDay</td>"; } $currentDay++; $dayOfWeek++;?>[/code]I tried removing the while($currentDay <= $noDays) and the script loaded fine. You may want to revise that (perhaps use an IF statement instead... although I'm not quite sure what you're doing with the script, so I cannot suggest much). Quote Link to comment Share on other sites More sharing options...
Barand Posted August 19, 2006 Share Posted August 19, 2006 <?phpwhile ($currentDay <= $noDays) [color=red]{[/color] if ($dayOfWeek == 7) { $dayOfWeek = 0; $calendar .= "</tr><tr>"; } $calendar .= "<td>$currentDay</td>"; [color=red]}[/color] $currentDay++; $dayOfWeek++;?>The $currentday is incremented OUTSIDE the while loop so you have an infinite loop. Quote Link to comment Share on other sites More sharing options...
sivarts Posted August 20, 2006 Author Share Posted August 20, 2006 Thanks, Barand. I SHOULD have realized that is what was happening. People in this forum rock. Quote Link to comment 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.