我想獲取使用日期類型的數據更改日期,從數據庫中獲取數據。但在此之後,被提取的數據包含要點擊的按鈕。點擊按鈕再次獲取數據。使用ajax在日期選擇使用php獲取數據
下面是代碼
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>
<body>
<form method="post">
<input type="date" name="gdate" id="gdate" onchange="<?php echo $_SERVER['PHP_SELF'] ?>"/>
</form>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<script>
function makeAjaxRequest(dateval) {
$.ajax({
type: "GET",
data: {dateva: dateval},
url: "fetchbills.php",
success: function (data) {
$('#showresult').html(data);
$('#det').on("click", function() {
var no = $(this).val();
makeAjaxRequest2(no);
});
}
});
}
function makeAjaxRequest2(billno) {
$.ajax({
type: "GET",
data: {bno: billno},
url: "fetchbilldetail.php",
success: function (data) {
$('#showresult').html(data);
}
});
}
$("#gdate").on("change", function() {
var id = $(this).val();
makeAjaxRequest(id);
});
</script>
<div id="showresult">
</div>
</body>
</html>
fetchbills.php
<?php
include("./config.php");
$dt = $_REQUEST["dateva"];
$sql = "select bill_id,order_id from bill_master where order_date='$dt'";
echo $sql;
$result = mysqli_query($con, $sql) or die("error");
if ($result) {
while ($row = mysqli_fetch_array($result)) {
echo $row[0] . "<br>";
echo "<form method='post' action=''><input type='submit' name='det' value='" . $row[1] . "' onclick='get(this.value)' /></form>
<div id='show'></div>";
}
}
?>
使用上述我得到命令id.The ID是顯示在按鍵的形式。 點擊按鈕我想獲得訂單id.but的詳細信息,但我做什麼我不明白。
我是新來的阿賈克斯,不知道該怎麼做。
這裏的代碼爲訂單詳情按照您的fetchbills.php
文件更改
<?php
include("./config.php");
$det = $_GET["bno"];
//echo $det;
$sql = "SELECT m.old_order_id,m.old_order_amount,l.item_id,l.old_order_quantity,i.item_name from old_order_master m,old_order_list l,item_list i where m.old_order_id=$det and m.old_order_id=l.old_order_id and l.item_id=i.item_id";
//echo $sql;
$result = mysqli_query($con, $sql);
echo "<table><tr><th>Item Name</th><th>Quantity</th></tr>";
while ($row = mysqli_fetch_array($result)) {
echo "<tr><td>" . $row[4] . "</td><td>" . $row[3] . "</td></tr>";
}
echo "</table>";
?>
你有任何錯誤消息? –
沒有錯誤,但我沒有得到另一個數據,即點擊按鈕上的訂單詳情。 –
任何人都可以提出建議,必須儘快完成。 –