index.php Hello community. I am using a dropdown list populated from mySQL using AJAX. I got this script as my base from a website that a member of this community suggested and you can see the demo here
In the demo there are 3 dropdowns and I am trying to make it 4, without luck as you can see in the screenshot here
I can not get the 2010 and pass it to the year so the 4th dropdown to show the selected rows, so it is shown as undefined.
One note though, if from the file findEngine.php remove the AND model_year='$yearId'
and leave it with only 1 AND
, it shows all the rows found for AUDI, not with the selected model or year of course.
I added the source codes below and the index.php to an external service because of it's length.
Any help is appreciate for this, I guess it is a beginners problem but I can not see it..
index.php http://codepad.org/k3n7HJ4G
findModel.php
<?
$make=$_GET['make'];
mysql
$query="SELECT distinct model_name FROM cars WHERE model_make_id='$make' order by model_name asc";
$result=mysql_query($query);
?>
<select name="model" onchange="getyear('<?=$make?>',this.value)">
<option>Select Model</option>
<? while($row=mysql_fetch_array($result)) { ?>
<option value=<?=$row['model_name']?>><?=$row['model_name']?></option>
<? } ?>
</select>
findYear.php
<? $makeId=$_GET['make'];
$modelId=$_GET['model'];
echo $modelId;
mysql
$query="SELECT distinct model_year FROM cars WHERE model_make_id='$makeId' AND model_name='$modelId' order by model_year asc";
$result=mysql_query($query);
?>
<select name="year" onchange="getEngine('<?=$makeId?>',this.value)">
<option>Select year</option>
<? while($row=mysql_fetch_array($result)) { ?>
<option value=<?=$modelId?>><?=$row['model_year']?></option>
<? } ?>
</select>
findEngine.php
<? $makeId=$_GET['make'];
$modelId=$_GET['model'];
$yearId=$_GET['year'];
echo $yearId;
mysql
$query="SELECT distinct model_trim FROM cars WHERE model_make_id='$makeId' AND model_name='$modelId' AND model_year='$yearId' order by model_trim asc";
$result=mysql_query($query);
?>
<select name="engine">
<option>Select year</option>
<? while($row=mysql_fetch_array($result)) { ?>
<option value><?=$row['model_trim']?></option>
<? } ?>
</select>