我有一个网站向客户销售一些产品。
我希望在将新订单插入mysql数据库时弹出或发出警告通知。
我被搜查了几个小时,找到了一个带有ajax的解决方案,但我现在仍然坚持使用ajax。
如果我只能收到通知,那么我不需要复杂的方法。
如果有人给我提示或更详细的参考或指南......非常感谢!
这是mysql插入查询:
$result2 = mysqli_query($con, "INSERT into user (emailPrefix,password1,address,address2,orderRnd,dateEmail,name5,phone, date)
VALUES ('$emailPrefix','$password1','$address','$address2','$orderRnd','$dateEmail','$name5','$phone','$date')");
答案 0 :(得分:1)
ajax.js
var interval = setInterval( function() {
$.ajax ({
url: "user.php",
success: function(data) {
$("#users").html(data);
}
});
}, 3000);
Above syntax refreshes pages every 3 seconds. You can compare old id of table in every 3 seconds. If new id is there eventually its new inserted values. So popup like below
$result2 = mysqli_query($con, "SELECT id FROM user ORDER BY id ASC");
while($rows = mysqli_fetch_assoc($result2)) {
$NEW_id = $rows["id"];
}
if($NEW_id > $_SESSION["OLD_id"]) {
$_SESSION["destination_OLD"] = $id_flexi;
echo '<audio controls="controls" autoplay>
<source src="beep.wav" type="audio/wav">
<embed src="beep.wav">
Your browser is not supporting audio
</audio>';
}
I have same problem as yours and this is my solutions. Experts recommend other things but I have only this much knowledge.
Good day.
答案 1 :(得分:0)
if($result2){
echo '<script type="text/javascript">alert("' . $msg . '")</script>';
} // define $msg as you like
答案 2 :(得分:0)
试试这个:
将此 html 音频标签和模态放在您想要发出哔声的页面上。
<audio id="playMusic" playcount="2">
<source src="https://media.geeksforgeeks.org/wp-content/uploads/20190531135120/beep.mp3" type="audio/mpeg">
</audio>
<!-- Modal -->
<div id="myModal" class="modal fade" role="dialog" data-backdrop="static" data-keyboard="false">
<div class="modal-dialog">
<!-- Modal content-->
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" onclick="javascript:window.location='dashboard.php?page=5'">×</button>
<h4 class="modal-title"><i class="fas fa-bell" ></i> Incoming Order!</h4>
</div>
<div class="modal-body">
<p>Find out the new order by: <a href="dashboard.php?page=5" class="text-info" >Click Here!</a></p>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal" onclick="javascript:window.location='dashboard.php?page=5'">Take me there!</button>
</div>
</div>
</div>
</div>
JS
js 代码会从 php 页面中获取新订单的数量,看看是否有新订单。
var old_count = 0;
var i = 0;
setInterval(function(){
$.ajax({
type : "POST",
url : "<?php echo 'folder/count_new_order.php'; ?>",
success : function(data)
{
if (data > old_count)
{
if (i == 0)
{old_count = data;}
else
{
$(document).ready(function() {
$("#playMusic").get(0).play();
});
$("#myModal").modal("show").on("shown", function () {
window.setTimeout(function () {
$("#myModal").modal("hide");
}, 1000);
});
old_count = data;
}
} i=1;
}
});
},500);
count_new_order.php
例如,该表已有 12 行。
include('config.php'); //db connection
$sql = "SELECT count(*) as count FROM table";
$qry = mysqli_query($conn,$sql);
$rowq = mysqli_fetch_assoc($qry);
echo $rowq['count']; // output: 12