繁体   English   中英

在创建通知/警报时,如何知道何时将通知标记为已读

[英]In creating notifications/alerts, how to know when to mark the notification as read

我正在使用PHP和MySQL创建一个网站,当前正在处理一个处理通知的页面(例如,当某人对您的帖子发表评论时,您会收到有关该通知的通知)。 该通知不是作为电子邮件发送,而是作为您登录帐户(Facebook风格)时网站上的警报发送。

现在,我的问题是确定何时将通知标记为已读。 简而言之:发生什么事件(例如单击,查看)是什么,可以确保通知已被读取,并且可以将其更改为已读?

但我已经解决了。 让我分享一下可能对某人有帮助:每个警报都应将用户定向到某个URL,例如,如果有人对您的帖子发表了评论,则在单击警报时应将您定向到“ www.example.com/posts/? post_id = 5”。 我将此作为目标网址。 生成警报时,我将其目标URL和警报详细信息存储在警报表中,并获取AI唯一字段(alert_id),我将使用该字段来生成警报上任何链接的href部分,例如<a href="changetoread.php?alert_id=56">G Thuo</a>对您的帖子发表了评论。 这是我的方法:在单击任何警报时,它首先将您带到其状态更改为已读的位置(基于链接中的alert_id)。 更改为读取后,然后我们从表中获取目标URL并在那里重定向用户。 这是我的代码:

$alert_id=$_GET['alert_id'];
$user_id=$_SESSION['user_id'];
//create the SQL to update the read_status
$sql="UPDATE alerts_log SET read_status=1 WHERE alert_id=$alert_id AND user_id=$user_id";
$res=mysql_query($sql) or die(mysql_error());
//we can now extract the targer_url from the alerts table and redirect the user automatically to that URL
$sql="SELECT target_url FROM alerts WHERE alert_id=$alert_id";
$res=mysql_query($sql) or die(mysql_error());
$row=mysql_fetch_assoc($res);
$url=$row['target_url'];
//redirect the user to that URL
header("Location: $url");

`

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM