Jump to content

while statement in drop down menu?


garyed

Recommended Posts

I'm having a problem with populating a second drop down menu that needs to be identical to the first from a mysql database.

I have about 20 items in the DB & I only want to show the first 9.

My code is:

      <select name="a_type" style="width: 175px;"> <option value="" selected="selected"> None selected</option> 
      <?php
$i=1;
while (($_produce = mysql_fetch_array($result_produce)) && ($i <=9 ))
{
$produce_type=$_produce["type"];
$produce_id=$_produce["id"];
$i++;
?>

<option value="<?php echo $produce_id; ?>"><?php echo $produce_id; ?> - <?php echo $produce_type; ?> </option>
<?php
}
?>
        </select>

 

That works fine in my first drop down menu but the second drop down menu with the same exact code will show items starting at 11 & higher

instead of 1 to 9. I haven't tried closing the DB & the reopening it which I assume would work but there are a lot of other variables & things I'd

have to check to make sure they don't get effected so I'd rather not.  Is there a simple way to solve this? 

 

Link to comment
https://forums.phpfreaks.com/topic/236872-while-statement-in-drop-down-menu/
Share on other sites

I appreciate the help but I've been messing with it all day & still haven't gotten it.

I can get the pointer back to whatever number I put in the argument but I just get that same number 8 times.

I even tried reset() & that helped a little populating the drop down but it locked up the database.

If  anyone could show me how to fix my code that would be greatly appreciated. 

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.