Populating menu from database problem
| From: | Mike Tuller | Date: | Tue, 15 Apr 2003 20:16:05 +0000 |
| Subject: | Populating menu from database problem | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-144016@lists.php.net to get a copy of this message | ||
This is weird, but I have an issue where I have a page for editing assets that have been entered into a database table. I have an editing page, that displays the information by filling in the fields so that I can edit it them. In that editing page, I have a menu that shows the selected item as the value for what was entered into the table of that item, has one item that displays as a blank, but it's value is set as non/don't know, then is populated by the items in a different table. In this case the populated values are for operating systems. So for instance, I created an asset, and set the operating system to Mac OS X, on the editing page, the selected value is set to Mac OS X. So it looks like this.
Mac OS X
Mac OS 9.2.2
Mac OS X
Windows XP
etc.
The top value is pulled from the value set in the operating_system column of the asset table, the other operating systems are from an operating_system table.
the problem I am having is that when I select an item listed from the operating_system table, it saves correctly, but if I leave the Mac OS X(or whatever other value is set from the asset table) it saves the value as being Mac. It's not blank, it just drops the OS X. I have looked over this again and again, and can't see why it is doing this.
Here is my code:
// asset database
$query = "select * from software_assets where asset_id = '$_SESSION[id]'";
$db_query = mysql_query ($query, $db_connect) or die (mysql_error());
$row = mysql_fetch_array($db_query);
// populate the menu with what the asset is set with, and the items in the operating_system table
//operating system menu showing the value already in the database
$operating_system_query = "SELECT * FROM operating_systems ORDER BY operating_system_name";
$operating_system_result = mysql_query($operating_system_query, $db_connect) or die (mysql_error());
// setup the menu and print out the blank selection
echo
"<font face=\"Arial,Helvetica,Geneva,Swiss,SunSans-Regular\">
Operating System: <select name=\"operating_system\" size=\"1\">
";
// take value from the row of the asset being edited then display information from operating_system table
echo
"<option selected value=$row[operating_system]>$row[operating_system]</option>
<option value=\"none/don't know\"></option>
";
while ($operating_system_row = mysql_fetch_array( $operating_system_result ))
{
$operating_system = $operating_system_row['operating_system_name'];
echo
"<option value='$operating_system'>$operating_system</option>
";
}
I hope this all makes sense.
Mike