Selecting Drop Down Value From DB to Edit

From: Date: Tue, 26 Mar 2002 23:22:01 +0000
Subject: Selecting Drop Down Value From DB to Edit
Groups: php.db 
Request: Send a blank email to php-db+get-17942@lists.php.net to get a copy of this message
I have the below code that populates a drop down list. The code will correctly insert the value $StateID into another a table. The problem I am running into is that when I select the record to edit the drop-downlist has the first option as the value instead of what the corresponding StateID in the column reads. How can I correct this? The form to insert and edit have the below code and correctly insert the StateID. I tried to write and if statement to state that if the StateID were == to the StateID in he table then print selected, but I think I am missing something. Any suggestions? Thanks. <?php // populates state drop-down list $get_stateid_query = mysql_query("SELECT * FROM State INNER JOIN RaceResults ON State.StateID WHERE RaceID='$RaceID'"); echo " <select name=\"StateID\">\n"; while ($myrow = mysql_fetch_array($get_stateid_query)) { echo ' <option value="'.$myrow["StateID"].'">'.$myrow["StateName"]."</option>\n"; } echo " </select>\n"; ?>

« previous php.db (#17942) next »