我有一个带有表“id”“year”“make”“model”“accu”的数据库“vehicles”。
我有 4 个下拉菜单,当您按下提交时,您会获得选定的值:
它几乎可以工作,但我的最后一个函数有问题......当显示最后一个下拉列表时,我可以选择所有与年份匹配的 accu......
例如,当我从 2013 年开始拥有 50 辆汽车时,它将显示所有与我选择的年份相匹配的精确度。
如何更改最后一个函数,它只显示与“make”、“model”和“year”匹配的 accu?
到目前为止,这是我的脚本:
<?php
//**************************************
// Page load dropdown results //
//**************************************
function getTierOne()
{
$result = mysql_query("SELECT DISTINCT make FROM vehicles ORDER BY make ASC")
or die(mysql_error());
while($tier = mysql_fetch_array( $result ))
{
echo '<option value="'.$tier['make'].'">'.$tier['make'].'</option>';
}
}
//**************************************
// First selection results //
//**************************************
if (isset($_GET['func'])&& $_GET['func'] == "drop_1" ) {
drop_1($_GET['drop_var']);
}
function drop_1($drop_var)
{
include_once('db.php');
$result = mysql_query("SELECT DISTINCT model FROM vehicles WHERE make='$drop_var' ORDER BY model")
or die(mysql_error());
echo '<select name="drop_2" id="drop_2">
<option value=" " disabled="disabled" selected="selected">Selecteer Model</option>';
while($drop_2 = mysql_fetch_array( $result ))
{
echo '<option value="'.$drop_2['model'].'">'.$drop_2['model'].'</option>';
}
echo '</select>';
echo "<script type=\"text/javascript\">
$('#wait_2').hide();
$('#drop_2').change(function(){
$('#wait_2').show();
$('#result_2').hide();
$.get(\"func.php\", {
func: \"drop_2\",
drop_var: $('#drop_2').val()
}, function(response){
$('#result_2').fadeOut();
setTimeout(\"finishAjax_tier_three('result_2', '\"+escape(response)+\"')\", 400);
});
return false;
});
</script>";
}
//**************************************
// Second selection results //
//**************************************
if (isset($_GET['func'])&& $_GET['func'] == "drop_2" ) {
drop_2($_GET['drop_var']);
}
function drop_2($drop_var2)
{
include_once('db.php');
$result = mysql_query("SELECT DISTINCT year FROM vehicles WHERE model='$drop_var2'")
or die(mysql_error());
echo '<select name="drop_3" id="drop_3">
<option value=" " disabled="disabled" selected="selected">Selecteer Jaar</option>';
while($drop_3 = mysql_fetch_array( $result ))
{
echo '<option value="'.$drop_3['year'].'">'.$drop_3['year'].'</option>';
}
echo '</select>';
echo "<script type=\"text/javascript\">
$('#wait_3').hide();
$('#drop_3').change(function(){
$('#wait_3').show();
$('#result_3').hide();
$.get(\"func.php\", {
func: \"drop_3\",
drop_var: $('#drop_3').val()
}, function(response){
$('#result_3').fadeOut();
setTimeout(\"finishAjax_tier_four('result_3', '\"+escape(response)+\"')\", 400);
});
return false;
});
</script>";
}
//**************************************
// Second selection results //
//**************************************
if (isset($_GET['func'])&& $_GET['func'] == "drop_3" ) {
drop_3($_GET['drop_var']);
}
function drop_3($drop_var3)
{
include_once('db.php');
$result = mysql_query("SELECT * FROM vehicles WHERE year='$drop_var3'")
or die(mysql_error());
echo '<select name="drop_4" id="drop_4">
<option value="" disabled="disabled" selected="selected">Selecteer Accu</option>';
while($drop_4 = mysql_fetch_array( $result ))
{
if ($drop_4['accu'] != "") {
echo '<option value="'.$drop_4['accu'].'">'.$drop_4['accu'].'</option>';
}
}
echo '</select> ';
echo '<input type="submit" name="submit" value="Submit" />';
}
?>