I am using a table for my states and I am having a time making the return value match what was already recorder in the DB I am using the following to populate the options list:
<label class="label" for="state"><em>State</em></label>
<select class="select" maxlength="30" id="" name="state" ><option>
<?php
$options = "";
while ($row = mysql_fetch_array($resultstate))
{
$name=$row["name"];
$abbrev=$row["abbrev"];
$options.="<OPTION VALUE=\"$abbrev\">".$name;
}
echo $options;
</option></select></div>
How can i loop through the array of states, or just tag the one in the DB as selected? I can do both seperatly, but not together...
Any help is greatly appreciated
With some tweaking:
while ($row = mysql_fetch_array($resultstate))
{
$name = $row["name"];
$abbrev = $row["abbrev"];
if($state == $abbrev){
echo '<OPTION VALUE="'.$abbrev.'" selected="selected">'. $name.' </OPTION>';
} else {
echo ' <OPTION VALUE="'.$abbrev.'"> '.$name.' </OPTION>';
}
}
Works correctly, thank you for pointing me in the right direction