我想从两个下拉列表组成的页面传递两个变量做一些计算并将第三个列表检索到div。我怎样才能使这个工作。? 这是我的代码。使用ajax和php页检索列表
<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”列名,结果存储到一个下降downlist
<?
$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>";
?>
你不说什么是不工作 –
道歉:)。我想从日期列表中选择一个值,以便医生和日期的相应值进入time.php脚本。从数据库中检索一些数据并将其放入列表中,并将此列表'时间'显示在主页。 – Ajit
你的php很容易被mysql注入 – DGS