1.Html文件
这里我有3个组合框。 第二个组合框取决于第一个组合框,第三个组合框应取决于第二个组合框。
我试图显示第二个查询(我的意思是单独使用php),它完全正常工作。
简单的值不是从第二个组合框传递到php文件。 (数据:' sub =' + SUB,//值不通过)。 $ rowCount = mysql_num_rows($ query); // $ rowcount在第二个组合框中始终为NULL。
<html><!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<style type="text/css">
.select-boxes{width: 280px;text-align: center;}
select {
background-color: #F5F5F5;
border: 1px double #FB4314;
color: #55BB91;
font-family: Georgia;
font-weight: bold;
font-size: 14px;
height: 39px;
padding: 7px 8px;
width: 250px;
outline: none;
margin: 10px 0 10px 0;
}
select option{
font-family: Georgia;
font-size: 14px;
}
</style>
<script src="jquery.min.js"></script>
<script type="text/javascript">
$(document).ready(function(){
$('#sem').on('change',function(){
var SEM = $(this).val();
if(SEM){
$.ajax({
type:'POST',
url:'sta.php',
data:'sem='+SEM,
success:function(html){
$('#sub').html(html);
$('#staff').html('<option value="">Select sub first</option>');
}
});
}else{
$('#sem').html('<option value="">Select batch first</option>');
$('#sub').html('<option value="">Select sem first</option>');
}
});
$('#sub').on('change',function(){
var SUB = $(this).val();
if(1){
$.ajax({
type:'POST',
url:'sta.php',
data:'sub='+SUB, //VALUE IS NOT PASSING
success:function(html){
$('#staff').html(html);
}
});
}else{
$('#staff').html('<option value="">Select sub first</option>');
}
});
});
</script>
</head>
<body>
<div class="select-boxes">
<form name="signup" method="POST" action="feedform.php">
<br><br><br><br>
<select id="sem" name="sem">
<option value="" selected>Select current semester</option>
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
</select><br><br><br>
<select name="sub" id="sub">
<option value="">Select semester first</option>
</select>
<select name="staff" id="staff">
<option value="">Select sub first</option>
</select>
</form>
</div>
</body>
</html>
2.sta.php
<?php
include("../Mine/connection.php");
if(isset($_POST["sem"]) && !empty($_POST["sem"]))
{
$query = mysql_query("SELECT course_name FROM subject WHERE semester =".$_POST['sem']);
//Count total number of rows
$rowCount = mysql_num_rows($query);
if($rowCount > 0){
echo '<option value="">Select course</option>';
while($row = mysql_fetch_assoc($query)){
echo '<option value="'.$row['course_name'].'">'.$row['course_name'].'</option>';
}
}else{
echo '<option value="">course not available</option>';
}
}
if(isset($_POST["sub"]) && !empty($_POST["sub"]))
{
$query = mysql_query("SELECT staff_name FROM subject WHERE course_name = ".$_POST['sub']);
//Count total number of rows
$rowCount = mysql_num_rows($query);
if($rowCount > 0){
echo '<option value="">Select Staff</option>';
while($row = mysql_fetch_assoc($query)){
echo '<option value="'.$row['staff_name'].'">'.$row['staff_name'].'</option>';
}
}else{
echo '<option value="">Staff not available</option>';
}
}
?>