Jump to content

[SOLVED] select option help


dennismonsewicz

Recommended Posts

I have the following html select

 

echo '<select name="company">';															
	echo '<option value="" selected="selected">' . $results->company . '</option>';
	echo '<option value="Health Resources">company1</option>';
	echo '<option value="True Health">company2</option>';
	echo '</select>';

 

The DB is going to house company 1 or company 2 depending upon the company selected at the time the user was creating this entry. Well I am wanting to make it where if company1 is in the DB then it doesn't repeat itself in the select list. And vice versa for company2.

 

Any ideas?

Link to comment
Share on other sites

$sql = mysql_query("SELECT company FROM table") or die(mysql_error());

$row = mysql_fetch_assoc($sql);

if($row['company']=="company 1")

{

$option = "<option name='company 2'>company 2</option>";

} else {

$option = "<option name='company 1'>company 1</option>";

}

$var = "<select name='company'>";

$var .= $option;

$var .="</select>";

 

obviously this can be built on but I hope this gives you the general idea

Link to comment
Share on other sites

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.