View Full Version : Auto fill dropdown list error

01-24-2007, 05:18 AM
Hi Guys,

Im using the code below to autofill a dropdown list from my MYSQL DB.
The only problem is it is leaving out the first entry (alphabetically) for each $vehicle_make ????

Does anyone know why this may be hapenning?

<select name="vehicle_model" class="textbox">
<option value="">select a type</option>

require_once ('../mysql_connect.php');

$query = mysql_query("SELECT model FROM Vehicles WHERE make='$_GET[vehicle_make]' ORDER BY model"); // autofill dropdown list 'select' with options from DB
$r = mysql_fetch_array($query);

while($r = mysql_fetch_assoc($query)) {
echo '<option value="'.$r['model'].'">'.$r['model'].'</option>';


make='$_GET[vehicle_make]' An example of this data is (Honda, Ford, Toyota)

01-24-2007, 05:36 AM
The following line of your code fetches a row from the result set, but does not use it.
$r = mysql_fetch_array($query); Why are you doing that?

01-24-2007, 05:39 AM
you have to state the result dont you?

01-24-2007, 06:10 AM
I got it sorted by removing the line below, thank you :)

$r = mysql_fetch_array($query);