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
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.

Link to comment
Share on other sites

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.

 

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.