Desperately need help with array and <select>

From: Date: Tue, 12 Sep 2000 13:57:35 +0000
Subject: Desperately need help with array and <select>
Groups: php.general 
Request: Send a blank email to php-general+get-16354@lists.php.net to get a copy of this message
First of all I am about 2 weeks new to PHP (disclaimer). :-) I have a MySQL database table that is holding the values of <option> for a select statement. The table has columns for heading, option_value, and html_value .I have succesfully created the array and it will create the drop down box very nicely. Here's that code: //Create SQL Statement $sql = "SELECT * FROM categories ORDER BY heading ASC"; //Execute SQL query and get results $sql_result = mysql_query($sql, $connection) or die ("Couldn't execute query"); <? echo " <select name=\"item_type\"> <option value=\"\"> -- Select an Category -- </option> "; $heading_value_test = ""; while ($row = mysql_fetch_array($sql_result)) { while ($row["heading"] <> $heading_value_test) { $heading_value_test = $row["heading"]; echo "<option value=\"\" STYLE=\"color: blue\"> -- $heading_value_test --</option>"; } $option_value = $row["option_value"]; $html_value = $row["html_value"]; echo "<option value=\"$option_value\">$html_value</option>"; } ?> I have a second table that holds product info, one of those columns is item_type, which is basically the same as option_value from the categories table. Here's what I want to do: When a user selects the product that they want to modify from within a form it takes them to a second form which fills all the product info into the form <input> and automatically selects the correct category within the <select><option>. Of course the remaining categories would be echo'ed to the other <option> tags. I can get all the <input> fields flawlessly, but this <select><option> stuff has me baffled. Any help would be GREATLY appreciated. TIA, Shane

« previous php.general (#16354) next »