Hello all,
Thanks to craig, in another post, I have a piece of code that will dynamically re-populate a select field with the selected option if the form has to be submitted again for validation.
<TD>Password Hint:</TD>
<TD>
<SELECT name=hint>
<OPTION VALUE=maiden<? if ($hint == 'maiden') print " selected"; ?>>Mother's maiden name?
<OPTION VALUE=color<? if ($hint == 'color') print " selected"; ?>>Your favorite color?
<OPTION VALUE=dog<? if ($hint == 'dog') print " selected"; ?>>Your dogs name?
<OPTION VALUE=eatery<? if ($hint == 'eatery') print " selected"; ?>>Your favorite restaurant?
</SELECT>
</TD>
This code works well for the static nature of this select statement.
However, I am dynamically generating the options for a select list options from a database and I cannot figure out how to redisplay the selected option if the form must be resubmitted to the user for correction.
This is the code that I am using to generate the option statements.
function populateselectoptions();
{
// Set up table query
$thisconnect = user_account_db_connect();
$local_qry = "select state_prov from stat_prov";
$result = mysql_query( $local_qry ) or die ( mysql_error() );
// Construct HTML code
if ( $result )
{
while ( $row = mysql_fetch_array( $result, MYSQL_ASSOC ) )
{
while( list ($key, $value) = each($row) )
{
echo "<option";
echo " value=" . ">";
echo "$value \n";
}
}
}
} // End populateselectoptions
No matter how I try to incorporate the following code into the option statement above parts of the php code will end up displaying in the field and will not print the selected option on the second draw of the form after a failed validation.
I hope someone can assist me, I have already lost enough hair, and the rest is going fast.
John