我是php的新手,我想知道是否有办法让这个脚本从db中读取用户的所有事件并触发弹出通知,例如“John就像你的照片”或“Maria正在关注你像那样的东西,类似于facebook的蜂鸣器。任何帮助apreciated! 我已经开始使用这些代码了:
获取PHP代码:
<?php
//fetch-popup-notification.php;
include("connect.php");
$query = "SELECT * FROM notification_users WHERE status = 0 ORDER BY id DESC";
$result = mysqli_query($connect, $query);
$output = '';
while($row = mysqli_fetch_array($result))
{
$output .= '
<div class="alert alert_default">
<a href="#" class="close" data-dismiss="alert" aria-label="close">×</a>
<p><strong>'.$row["subject"].'</strong>
<small><em>'.$row["notification"].'</em></small>
</p>
</div>
';
}
echo $output;
$update_query = "UPDATE notifications_users SET status = 1 WHERE status = 0";
mysqli_query($connect, $update_query);
?>
Ajax代码:
<script type="text/javascript">
$(document).ready(function(){
setInterval(function(){
load_last_notification();
}, 6000);
function load_last_notification()
{
$.ajax({
url:"notificari/fetch-popup-notification.php",
method:"POST",
success:function(data)
{
$('.notif-popup').html(data);
}
})
}
});
</script>
HTML:
<div id='alert_popover'>
<div class='wrapper'>
<div class='notif-popup'>
</div>
</div>
</div>
在DB中的我有:id |主题|通知|状态