fazzfarrell Posted June 5, 2007 Share Posted June 5, 2007 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 More sharing options...
Wildbug Posted June 5, 2007 Share Posted June 5, 2007 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>. Link to comment https://forums.phpfreaks.com/topic/54300-drop-down-from-database/#findComment-268564 Share on other sites More sharing options...
Yesideez Posted June 5, 2007 Share Posted June 5, 2007 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'. Link to comment https://forums.phpfreaks.com/topic/54300-drop-down-from-database/#findComment-268569 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.