PHP and HTML Form Help?

justinsbabe5000

New member
I have an html form that displays all the states in a drop down list. The user is asked to choose a state. When a state is chosen and the form is submitted another page loads with all data from a table that matches that date. The user then clicks on the update link next to each row of data and is sent to another page where there is a form that is filled in and they can update only what needs to be updated.

What I want to know how to do is create a drop down list where a certain element of the list is selected based on the variable that was set.

I have the drop down list populated but have yet to figure out how to get the right race to be selected.

Let's say we have the following in PHP:
$race = $_GET['race'];

I created a drop down list from the list of races in a database table in MySQL:
<select name="racecode">
<?php
# Select all from race table
$query = "select *
from race";

$result = mysql_query($query) or DIE("Unable to read data " . mysql_error());

while($row = mysql_fetch_array($result)){
?>
<option value = "<?php echo $row['racecode']; ?>"><?php echo $row['racename']; ?></option>
<?php
}
?>
</select>

Now how do I do the following:
fetch data from database
and if(value == $race)
create option and set selected
else
just create option

Is there even a way to do this?
 
Back
Top