Jump to content

poulate multiple dropdowns from mysql?


garyed

Recommended Posts

I have two drop down menus in a table side by side being populated exactly the same from a msql database.

The first menu populates fine but  the second one is blank.

They are both supposed to be identical, the same info from the same table so I assume that's my problem.

I tried moving the while loop so it encapsulates both drop downs but then it messes up the table structure.

I tried changing the name of some of the variables by adding "2" on the end  & that didn't work either.

Is it because once a while loop is executed it can't be used again on the same instance?

Heres my code so far:

      <tr>
        <td >   <select name="wall_type" size="1" style="width: 175px;" >      
<?php
while ($walls_row=mysql_fetch_array($result_walls))
{
$type_name=$walls_row["type"];   
$type_id=$walls_row["id"];    
?>
  <option value="<?php echo $type_id; ?>"><?php echo $type_name; ?>   </option>
<?php
}
?>
</select>
   </td>
<td >
<select name="wall_type2" size="1"  style="width: 175px;">
<?php
while ($walls_row2=mysql_fetch_array($result_walls))
{
$type_name2=$walls_row2["type"];   
$type_id2=$walls_row2["id"]; 

?>
<option value="<?php echo $type_id2; ?>"><?php echo $type_name2; ?>   </option>
<?php
}
?>
</select>
</td>
</tr>

Link to comment
https://forums.phpfreaks.com/topic/215210-poulate-multiple-dropdowns-from-mysql/
Share on other sites

once you've iterated over mysql_fetch_array($result) once, you can't do it again without resetting the pointer:

 

mysql_data_seek( $result );

 

personally, i would load the results in an array the first time through, then loop over the array for the second select. just personal preference.

Thanks for the help,

I'm not sure i understand though (I'm really a novice at this) I don't even know what a pointer is.

I thought  that  "mysql_fetch_array ( $result_walls) "  loaded the results into an array. 

I've got a lot more reading to do.

This stuff reminds me of how lost i was when I first started using Linux.

The tutorials are great once you get to a certain level but until then its like reading Hieroglyphics.

 

 

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.