Hi...
I'm not sure how to go about this.
My code is below:
// Create Flight Hours List Box //
$ref_hrs = "SELECT * FROM hrs_ref";
$ref_hrs_result = @mysql_query($ref_hrs, $connect) or die(mysql_error());
while ($row_refhrs = mysql_fetch_array($ref_hrs_result)) {
$refhrs = $row_refhrs['hrs_ref_list'];
if($_POST[hours] == "$refhrs") {
$hours_listsel = "<option value=$refhrs selected>$refhrs</option>";
}
$hours_list .= "<option value=$refhrs>$refhrs</option>";
$hours_list_box = "
<select name=hours>
<option value=9>Select One</option>
<option value=9>--------------------</option>
$hours_listsel
$hours_list
</option>";
}
This works ok... but I get a duplicate entry in the dropdown menu.
I have a page that allows the user to enter data from some form fields. Once they hit "Submit", it basically refreshes the page showing the same form fields with the data entered by the user in red so they can confirm their data before submitting it.
Naturally I want the drop down menu to show the user's selected data... and the code I have above works ok... but it shows the user's selected data as the first <option> in the menu followed by the rest of the data... including the same <option> selection as the user's.
For example, the original dropdown menu is thus:
<select name=hours>
<option value=9 selected>Select One</option>
<option value=9>--------------------</option>
<option value=1>1</option>
<option value=2>2</option>
<option value=3>3</option>
<option value=4>4</option>
<option value=5>5</option>
<option value=6>6</option>
</select>
On the confirmation page, after running the PHP script shown above, I get this (if the user has selected 3 for example):
<select name=hours>
<option value=9>Select One</option>
<option value=9>--------------------</option>
<option value=3>3</option> // This is the line that shows up in the drop down menu //
<option value=1>1</option>
<option value=2>2</option>
<option value=3>3</option>
<option value=4>4</option>
<option value=5>5</option>
<option value=6>6</option>
</select>
I'd like to be able to run code that configures the drop down menu so that the code appears like this:
<select name=hours>
<option value=9>Select One</option>
<option value=9>--------------------</option>
<option value=1>1</option>
<option value=2>2</option>
<option value=3 selected>3</option>
<option value=4>4</option>
<option value=5>5</option>
<option value=6>6</option>
</select>
... that way the correct value (ie, the user's selected one) shows in the drop down menu window, and is the selected value... and also doesn't duplicate the selected value's entry as with my current code.
I've worked on this for about a day now trying to figure out how to create a query that will work the way I want with no success.
Can anyone give me some advice? Thanks a lot....