Jump to content

[SOLVED] Drop Down With Assigned Value From Database


dlebowski

Recommended Posts

Is this scenario possible:

 

I have a database that has customers in it.  When they purchase things from me, each purchase is either "online" or "onsite".  So a selection must be made as either "online" or "onsite" when the item is entered into the database.  Often, I have to update this value for an item later on from "online" to "onsite" and vice versa.  Is there anyway to populate the "Type" field with whatever the value is in the datablse for this particular item purchased, then allow someone to select "online" or "onsite" from the dropdown if it needs to be edited?

It would look something like this:

Item Number (primary key) | Customer ID | Cost | Type (online or onsite)

            7897                        4              $3            online

 

The code below is kind of how I would envision it working, but have had little luck finding a good example in the forum or online anywhere.  Any help would be greatly appreciated.

 

<TD width=98 height="29" align="center"><select name='add_OnlineOnsite' value='default value from Type Field in DB'>
<option value="Online">Online</option>
<option value="Onsite">Onsite</option>
</select></td>

Here is what I ended up doing and it works.  Thankfully. 

 

Would enum make this more efficient?

 

<?
include("dbinfo.inc.php");

mysql_connect("localhost",$username,$password);
@mysql_select_db($database) or die( "Unable to select database");
$query = mysql_query("SELECT OnlineOnsite FROM items WHERE Buyer=$Buyer AND SellingDate=$SellingDate AND ItemID=$ItemID") or die(mysql_error());

while ($row = mysql_fetch_assoc($query))
{
echo '<select name="ud_OnlineOnsite">';
echo '<option'.($row['OnlineOnsite']=="Online"? ' selected' : '').'>Online</option>';
echo '<option'.($row['OnlineOnsite']=="Onsite"? ' selected' : '').'>Onsite</option>';
echo '</select>';
}
?>

 

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.