scarhand
scarhand

Reputation: 4337

date intervals of 15 minutes between 9-5

heres my code, all i want to do is echo the values so they come up in a SELECT input in the following format:

9:00 9:15 9:30 9:45 10:00 10:15 ETC.

heres my code which just crashes the page:

<select>
<option>Select Time</option>
<?php

for ($i = 9; $i <= 12; $i++)
{
    for ($j = 0; $j <= 45; $j+15)
    {
        echo '<option>'.$i.':'.str_pad($j, 2, '0', STR_PAD_LEFT).'</option>';
    }
}

?>
</select>

Upvotes: 0

Views: 1101

Answers (2)

s1lent1um
s1lent1um

Reputation: 159

Wrong $j increment. You should use this:

$j+=15

Upvotes: 1

Femi
Femi

Reputation: 64700

You're not properly incrementing the $j loop:

Do this:

<?php

for ($i=9;$i<=12;$i++){
  for ($j=0;$j<=45;$j=$j+15)
      {
        echo '<option>'.$i.':'.str_pad($j, 2, '0', STR_PAD_LEFT).'</option>';
      }
  }

?>

Upvotes: 1

Related Questions