Forum Moderators: coopster

Message Too Old, No Replies

Auto fill dropdown list error

         

adammc

4:19 am on Jan 24, 2007 (gmt 0)

10+ Year Member



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?

[PHP]<select name="vehicle_model" class="textbox">
<option value="">select a type</option>
<?php

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>';
}

?>
</select>[/PHP]

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

cameraman

5:36 am on Jan 24, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



You're getting the first value with

$r = mysql_fetch_array($query);

Then the 2nd through end inside the while.