cavey5 Posted May 25, 2007 Share Posted May 25, 2007 I have a subscription database that allows you to edit a subscribers data. For example, you enter a search term like "Bob" and it returns a list of everyone named Bob. You click the one you want and it goes to a subscriber detail page, where all of his data is populated to a form. You can directly edit this form and click save to overwrite it. The only issue is the select boxes (drop downs) - say I have four options in the drop down box, red, blue, green and black. On my details page for bob I end up with five, I have those four PLUS whatever was saved for his color, so it shows up twice. If Bob is green, my select box looks like: Green Red Blue Green Black How can I make it so that Green only shows up once? Quote Link to comment https://forums.phpfreaks.com/topic/52934-populating-a-select-box-from-a-database/ Share on other sites More sharing options...
Lumio Posted May 25, 2007 Share Posted May 25, 2007 <select name="colors"><?php $result = mysql_query('QUERY'); $row = mysql_fetch_assoc($result); $arr = array('Red', 'Blue', 'Green', 'Black'); foreach($arr as $s) { if (strtolower($s) != $row['color']) echo '<option value="'.$s.'">'.$s.'</option>'; } ?></select> Quote Link to comment https://forums.phpfreaks.com/topic/52934-populating-a-select-box-from-a-database/#findComment-261403 Share on other sites More sharing options...
cavey5 Posted May 25, 2007 Author Share Posted May 25, 2007 That doesn't seem to work because i am already inside this: while ($row = mysql_fetch_array($findsubscriber_result)) { $cm_company = $row["cm_company"]; $cm_phone = $row["cm_phone"]; $cm_email = $row["cm_email"]; etc. etc. Quote Link to comment https://forums.phpfreaks.com/topic/52934-populating-a-select-box-from-a-database/#findComment-261418 Share on other sites More sharing options...
Lumio Posted May 25, 2007 Share Posted May 25, 2007 than use only $arr = array('Red', 'Blue', 'Green', 'Black'); foreach($arr as $s) { if (strtolower($s) != $row['color']) echo '<option value="'.$s.'">'.$s.'</option>'; } Quote Link to comment https://forums.phpfreaks.com/topic/52934-populating-a-select-box-from-a-database/#findComment-261420 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.