Skip to main content
Inspiring
May 20, 2010
Answered

PHP loop increments greater than 1

  • May 20, 2010
  • 2 replies
  • 2614 views

Hi Folks,

I am trying to get a drop down menu to populate in increments of 10 and I can't seem to get it. It must be easy but searching the net doesn't seem to get me anywhere.

here's what I have at present:

----------------------------------------------------------------

<select name="distance_miles" class="formrightcolumnnarrow" id="distance_miles">

  <?php

  for( $i=0; $i<=1000; $i++ )

{?>

<option value="<?php echo$i;?>"><?php echo$i;?>

<?php ;} ?>

  </option>

  </select>

----------------------------------------------------------------

if I do the obvious and change $i++ to $i+10 the browser hangs.

Can anyone give me a clue how to make it work for a higher increment than 1?

Cheers

Dave

This topic has been closed for replies.
Correct answer bregent

$i++ is shorthand for $i=$i+1

So....

$i=$i+10

2 replies

Randy Edmunds
Adobe Employee
Adobe Employee
May 21, 2010
if I do the obvious and change $i++ to $i+10 the browser hangs.

Can anyone give me a clue how to make it work for a higher increment than 1?

$i++ is an abbreviation for:

  $i = $i + 1;

So, use:

  $i = $i + 10;

HTH,

Randy

Randy Edmunds
Adobe Employee
Adobe Employee
May 21, 2010

Dang, I need to refresh my list more often

bregentCorrect answer
Participating Frequently
May 20, 2010

$i++ is shorthand for $i=$i+1

So....

$i=$i+10

davecheetAuthor
Inspiring
May 21, 2010

Great thanks,

I am truly dumb.

Cheers

Dave