Jump to content

Recommended Posts

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?

Link to comment
https://forums.phpfreaks.com/topic/52934-populating-a-select-box-from-a-database/
Share on other sites

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

 

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.

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.