dlebowski Posted May 29, 2007 Share Posted May 29, 2007 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> Quote Link to comment https://forums.phpfreaks.com/topic/53439-solved-drop-down-with-assigned-value-from-database/ Share on other sites More sharing options...
redarrow Posted May 29, 2007 Share Posted May 29, 2007 look up ENUM for mysql. that database field type would result as online or onsite with a if statement. Quote Link to comment https://forums.phpfreaks.com/topic/53439-solved-drop-down-with-assigned-value-from-database/#findComment-264064 Share on other sites More sharing options...
dlebowski Posted May 29, 2007 Author Share Posted May 29, 2007 Thanks for replying so quickly. So can i use enum in conjunction with a drop down? Quote Link to comment https://forums.phpfreaks.com/topic/53439-solved-drop-down-with-assigned-value-from-database/#findComment-264071 Share on other sites More sharing options...
redarrow Posted May 29, 2007 Share Posted May 29, 2007 to show the result from the database yes Quote Link to comment https://forums.phpfreaks.com/topic/53439-solved-drop-down-with-assigned-value-from-database/#findComment-264077 Share on other sites More sharing options...
dlebowski Posted May 29, 2007 Author Share Posted May 29, 2007 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>'; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/53439-solved-drop-down-with-assigned-value-from-database/#findComment-264122 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.