我试图从由两个下拉列表组成的页面中传递两个变量进行一些计算并将第三个列表检索到 div 中。我怎样才能让它工作。?这是我的代码。
<HTML>
<HEAD>
<script src="jquery-1.10.2.js"></script>
<script type="text/javascript">
$(document).ready(function(){
$("#day").change(function(){
var day=$("#day").val();
var doctor=$("#doctor").val();
$.ajax({
type:"post",
url:"time.php",
data:"day="+day+"&doctor="+doctor,
success:function(data){
$("#testing").html(data);
}
});
});
});
</script>
</HEAD>
<BODY>
<FORM action="post">
<SELECT id="doctor">//some options</SELECT>
<SELECT id="day">//some option </select>
<div id="testing">
BLA BLA BLA
</div>
</BODY>
</HTML>
在 time.php 页面上,我进行了一些计算以检索位值为“1”的列名并将结果存储到下拉列表中
<?
$con=mysqli_connect("localhost","clinic","myclinic","myclinic");
// Check connection
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$doctor = $_POST['doctor'];
$day = $_POST['day'];
$query="SELECT * FROM schedule WHERE doctor='" .$doctor."'AND day='" .$day. "'";
//Some calculations and store the result into a list
$result = mysqli_query($con, $query);
if(!$result)
{
echo "Failed to execute the query";
}
echo"
<table><tr><td> Time </td>
<td> <select name='time'>";
$i = 0; //Initialize the variable which passes over the array key values
$row = mysqli_fetch_assoc($result); //Fetches an associative array of the row
$index = array_keys($row); // Fetches an array of keys for the row.
while($row[$index[$i]] != NULL)
{
if($row[$index[$i]] == 1) {
echo $index[$i];
echo "<option value='" . $index[$i]."'>" . $index[$i] . "</option>";
}
$i++;
}
echo "</select>";
?>