我想從兩個下拉列表組成的頁面傳遞兩個變量做一些計算並將第三個列表檢索到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