好吧,我正在阅读堆栈溢出给出的解决方案,但我找不到正确的解决方案......所以这是我的问题:
我创建一个有多个选择的表单(不是select multiple =“true”),不,我的意思是一个表单,让我们说4个不同的选择...从数据库中检索数据,所以如果我填写我的第一个“选择”让我说Style1然后我想得到“style1”选择所以我可以根据它来配置我的第二个选择查询,我可以DISTINCT我正在寻找的值...我不知道你是否得到了我的想法,我我读过我需要使用AJAX,但我无法弄清楚如何......
<form method="post">
<select name="category">
<?php $test = mysql_query("SELECT category FROM test_table GROUP BY category");
while($testing = mysql_fetch_array($test)){
echo "<option value=".$testing["category"].">".$testing["category"]."</option>";
}
?>
</select>
<select name="model">
<?php $test2 = mysql_query("SELECT model FROM test_table WHERE model = 'TRYING TO COMPARE WITH THE VALUE WITH THE FIRST SELECT' GROUP BY model");
while($testing2 = mysql_fetch_array($test2)){
echo "<option value=".$testing2["model"].">".$testing2["model"]."</option>";
</select>
</form>
那只是为了得到一个想法,不是真正的想法,而是一个非常接近的例子。
答案 0 :(得分:0)
<form method="post">
<select name="category" onchange="javascript:getDroupDownValues(this.value);">
<?php $test = mysql_query("SELECT category FROM test_table GROUP BY category");?>
<?php while($testing = mysql_fetch_array($test)):?>
<option value="<?php echo $testing["category"];?>"><?php echo $testing["category"];?></option>
<?php endwhile;?>
</select>
<div id="model-category">
</div>
</form>
<script type="text/javascript">
function getDroupDownValues(value)
{
jQuery.ajax({
dataType: "html",
type: "POST",
evalScripts: true,
url: 'your ajax url', // example your site url /ajax.php
data: ({category:value}),
success: function(data, textStatus) {
jQuery("#model-category").html(data);
}
});
}
</script>
现在在ajax.php脚本中
<?php if(isset($_REQUEST['category']) && $_REQUEST['category']):?>
<select name="model">
<?php $test2 = mysql_query("SELECT model FROM test_table WHERE model = '{$_REQUEST['category']}' GROUP BY model");?>
<?php while($testing2 = mysql_fetch_array($test2)):?>
<option value="<?php echo $testing2["model"];?>"><?php echo $testing2["model"];?></option>
<?php endwhile;?>
</select>
<?php endif;?>