douxin2011 2014-02-13 01:58
浏览 47

使用mySQL和PHP创建第四个AJAX填充下拉列表时出现错误是什么?

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

enter image description 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>
  • 写回答

1条回答 默认 最新

  • dongyi8795 2014-02-13 03:23
    关注

    As per the definition of getEngine function, it takes 3 parameters but you are passing only 2.

    Change below line in findEngine.php

    <select name="year"  onchange="getEngine('<?=$makeId?>',this.value)">
    

    To,

    <select name="year"  onchange="getEngine('<?=$makeId?>', '<?=$modelId?>', this.value)">
    

    Also, avoid using mysql extension as it is deprecated in PHP 5.5.0. Read http://www.php.net/manual/en/intro.mysql.php for the details and alternatives.

    评论

报告相同问题?

悬赏问题

  • ¥15 对于相关问题的求解与代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料
  • ¥15 使用R语言marginaleffects包进行边际效应图绘制
  • ¥20 usb设备兼容性问题
  • ¥15 错误(10048): “调用exui内部功能”库命令的参数“参数4”不能接受空数据。怎么解决啊
  • ¥15 安装svn网络有问题怎么办