Jump to content

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

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.