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
https://forums.phpfreaks.com/topic/124530-solved-select-option-help/
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

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.