Jump to content

drop down from database


fazzfarrell

Recommended Posts

I have a database with entries such as

Clo, Rel_ID Clo, Rel_ID Clo, Rel_ID

brown, 1 blue, 2 green, 1 etc

 

I have dropdown menus on the page which have the values from the database the are around 16 variations

 

I have to call in the database each time with the Rel_ID = '1' or '2' etc.

 

is ther a way where I can call in all the entries from the database then hard code the relevant ID on the page?

<select name="select">
              <?php
do {  
?>
              <option value="<?php echo $row_rsUser['Email']?>"><?php echo $row_rsUser['Email']?></option>
              <?php
} while ($row_rsUser = mysql_fetch_assoc($rsUser));
  $rows = mysql_num_rows($rsUser);
  if($rows > 0) {
      mysql_data_seek($rsUser, 0);
  $row_rsUser = mysql_fetch_assoc($rsUser);
  }
?>
            </select>

 

 

Link to comment
https://forums.phpfreaks.com/topic/54300-drop-down-from-database/
Share on other sites

What do you mean "hard code?"  If you just mean that you want a particular value to be selected as the default when the page loads, then place a comparison in your loop such that whenever the data value is equal to the one you're looking for, the output for that value will be: <option value="blah" SELECTED>blah</option>.

To save me posting the code twice you might find this useful:

 

http://www.phpfreaks.com/forums/index.php/topic,143743.0.html

 

That has code I've written for another user where it pulls the data from the table and uses the ID field as a value in 'option'.

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.