do {
?><option value="RATE" <?php
if (!(strcmp("RATE", $row_rsZipCode['zip_code']))) {
echo "selected=\"selected\"";
} ?>><?php
echo $row_rsZipCode['zip_code']; ?></option><?php
}
while ($row_rsZipCode = mysql_fetch_assoc($rsZipCode)); ?>
Ok. So this part of the code loops through all the rows returned by MySQL and provides all the options in the select drop down menu like this:
<option value="RATE">90210</option>
<option value="RATE">90211</option>
<option value="RATE">90212</option>
<option value="RATE">90213</option>
<option value="RATE">90214</option>
<option value="RATE">90215</option>
And that doesn't make any sense... is it possible that you modified the PHP before pasting it here? (It doesn't make sense because no matter which Zip Code the user chooses, the value is always the same... the word "RATE"... and that's pretty useless).
In general, here's how to do what you're trying to do:
$_REQUEST['drop_down_name'] is going to contain the VALUE of the OPTION that the user selected.
For example, if the user chooses zip code 90213 from the select statement below, then $_REQUEST['zip_xyz_field'] will be set to "4".
<select name="zip_xyz_field">
<option value="1">90210</option>
<option value="2">90211</option>
<option value="3">90212</option>
<option value="4">90213</option>
<option value="5">90214</option>
<option value="6">90215</option>
</select>
So what you want to do is this: As you are looping through all the database values and printing out each OPTION tag, you want to check to see if $_REQUEST['drop_down_name'] is equal to the VALUE that you are currently displaying and IF SO, then you want to print the word, "selected" because: The value that the user chose is the same as the value of the option that we are currently displaying. Like this:
do {
echo "<option value='" . $row_rsZipCode['cost'] . "'";
if ($_REQUEST['zip_xyz_field']==$row_rsZipCode['cost']) {
print " selected";
}
echo ">".$row_rsZipCode['zip_code']."</option>";
}
while ($row_rsZipCode = mysql_fetch_assoc($rsZipCode));
You can use this as a model where the IF statement simply compares the value passed in by the user to the value of the current option.