...

View Full Version : Auto fill dropdown list error



adammc
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>
<?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>


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

CFMaBiSmAd
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?

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

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


$r = mysql_fetch_array($query);



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum