我有2个下拉列表,分支下拉列表从数据库中获取app_cn。 sem下拉列表获取app_plan_no。但我需要在分支下拉列表中选择的值与sem下拉列表中选择的值进行比较。
我看到了这段代码,但我不知道该怎么做
<?php
$mysqli = new mysqli("localhost", "root", "", "app");
$result = $mysqli->query("SELECT * FROM app GROUP BY app_cn ORDER BY app_cn");
echo'<select name="drop_1" id="drop_1">';
while($row = $result->fetch_assoc())
{
echo '<option value="'.$row['app_cn'].'">'.$row['app_cn'].'</option>';
}
echo'</select>';
if($_GET['func'] == "drop_1" && isset($_GET['func'])) {
drop_1($_GET['drop_var']);
}
function drop_1($drop_var)
{
$mysqli = new mysqli("localhost", "root", "", "app");
$results = $mysqli->query("SELECT * FROM app WHERE app_cn='$drop_var' GROUP BY app_plan_no ORDER BY app_plan_no");
echo '<select name="tier_two" id="tier_two">
<option value=" " disabled="disabled" selected="selected">Choose one</option>';
while($drop_2 = $results->fetch_assoc())
{
if($drop_2['app_plan_no'] != '')
{
echo '<option value="'.$drop_2['app_plan_no'].'">'.$drop_2['app_plan_no'].'</option>';
}
}
}
echo'</select>';
?>
<script type="text/javascript">
$(document).ready(function() {
$('#wait_1').hide();
$('#drop_1').change(function(){
if( $(this).val() == "ALL") {
$("#wait_1").hide();
$("#result_1").hide();
}else{
$('#wait_1').show();
$('#result_1').hide();
$.get("func.php", {
func: "drop_1",
drop_var: $('#drop_1').val()
}, function(response){
$('#result_1').fadeOut();
setTimeout("finishAjax('result_1', '"+escape(response)+"')", 400);
});
}
return false;
});
});
function finishAjax(id, response) {
$('#wait_1').hide();
$('#'+id).html(unescape(response));
$('#'+id).fadeIn();
}
</script>
这就是我要做的事情WHERE app_cn='$drop_var'
我的表
counter | app_cn | app_plan_no
000004 | comp1 | 1
000172 | comp1 | 1
000007 | comp1 | 2
000005 | comp2 | 1
这是我的选择下拉列表
<select name="branch" id="branch" onchange="showCourses()">
<option value="ALL" selected='ALL'>ALL</option>
<?php
$mysqli = new mysqli("localhost", "root", "", "app");
$result = $mysqli->query("SELECT * FROM app GROUP BY app_cn ORDER BY app_cn");
while($row = $result->fetch_assoc())
{
echo '<option value="'.$row['app_cn'].'">'.$row['app_cn'].'</option>';
}?>
</select>
<select name="sem" id="sem" onchange="showCourses()">
<?php
$mysqli = new mysqli("localhost", "root", "", "app");
$result = $mysqli->query("SELECT * FROM app GROUP BY app_plan_no ORDER BY app_plan_no");
while($row = $result->fetch_assoc())
{
echo '<option value="'.$row['app_plan_no'].'">'.$row['app_plan_no'].'</option>';
}
?>
</select>
答案 0 :(得分:0)
使用jquery使用.val()
获取select语句的值要在使用php(服务器端)提交表单时获取select语句的值,您可以在$ _POST变量中找到变量的值,其中键是select语句的name属性的值。 / p>