Topic awaiting preservation: How do I set priority on the form tag SELECT? (Page 1 of 1) |
|
---|---|
Nervous Wreck (II) Inmate From: Kansas, just this side of the rainbow |
posted 12-22-2005 20:25
My problem is that I have a form with a SELECT tag that calls its options from a MySQL database. This works fine, but when I set the edit page to allow people to edit their entries, I want the select tag to list whatever the original entry had. code: <select name="zone" size="1"> <?php include( 'includes/loginstuff.php'); $order_name = "SELECT * FROM zone_table ORDER BY zone_name ASC"; $get_name = mysql_query($order_name, $login) or die (mysql_error()); while ($result = mysql_fetch_array($get_name)) { $id = $result['id']; $zone = $result['zone_name']; $display_zone .= "<option value=\"$id \">$zone</option>"; } ?> <?php echo $display_zone; ?> </select>
code: "SELECT * FROM zone_table WHERE id = $_GET[id]"; which works fine to get the previous option to list, but it only lists that option. I cannot seem to figure out a way to include both into this select tag and make it work. How do I write this so that I have the previous option listed first and still have all the other options listed below? |
Maniac (V) Inmate From: under the bed |
posted 12-22-2005 21:31
If I understand correctly, you have two main options - |
Paranoid (IV) Mad Scientist with Finglongers From: Germany |
posted 12-22-2005 21:43
Hm... you either want to have the current value at the top of the list - you'll need to built an array and for each fetched row, either append it, or unshift() it if it's the old entry for that. code: <select name="zone" size="1"> <?php include( 'includes/loginstuff.php'); $order_name = "SELECT * FROM zone_table ORDER BY zone_name ASC"; $get_name = mysql_query($order_name, $login) or die (mysql_error()); while ($result = mysql_fetch_array($get_name)) { $id = $result['id']; $zone = $result['zone_name']; if ($id == $_GET['id']) $display_zone .= "<option selected="true" value=\"$id \">$zone</option>"; else $display_zone .= "<option value=\"$id \">$zone</option>"; } ?> <?php echo $display_zone; ?> </select>
code: "SELECT * FROM zone_table WHERE id = $_GET[id]"; that's a security risk. at least make it "SELECT * FROM zone_table WHERE id = " . intval ( $_GET[id] ) ; |
Nervous Wreck (II) Inmate From: Kansas, just this side of the rainbow |
posted 12-22-2005 22:10
Thank you both of you. |