I am struggling with the following code and cant find a away to fix it. The page just takes too long to load and "Fatal error: Maximum execution time of 30 seconds exceeded" error appears.
Maybe someone could explain or give an advice?
<?php
$i = 1;
$s = 1;
$limit = 21;
$seasons = 6;
while ($s < $seasons) {
if ($s < 10) {
$s = '0' . $s;
}
while ($i < $limit) {
if ($i < 10) {
$i = '0' . $i;
}
echo '<input type="checkbox" value="S' . $s . 'E' . $i . '" name="rate"/>S' . $s . 'E' . $i . '<br/>';
++$i;
}
}
?>
Thank you
UPDATE:
After adding an $s++; at the end of firt loop the code was solved of errors and long load but it runs only once no respecting the $seasons = 6 condition. Any idea why would that happen? I tried to remove the 0 prefix and it still not looping till 6
UPDATE: Problem solved, second loop placed in function and it worked. Thanks to all!.
FINAL VERSION
<?php
$s = 1;
$limit = 21;
$seasons = 7;
while ($s < $seasons) {
if ($s < 10) {
$s = '0' . $s;
}
episodes($s,$limit);
$s++;
}
function episodes($s,$limit){
$i = 1;
while ($i < $limit) {
if ($i < 10) {
$i = '0' . $i;
}
echo '<input type="checkbox" value="S' . $s . 'E' . $i . '" name="rate"/>S' . $s . 'E' . $i . '<br/>';
++$i;
}
}
?>
$sanywhere, so it's always going to be less than$seasons(endless loop). You are adding a zero to the start of it, but that doesn't affect the loop... is that zero supposed to be at the end?