简体   繁体   English

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

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

I'm creating a website with PHP and MySQL, and currently working on a page that deals with notifications (eg When someone comments on a post by you, you get a notification to that effect). 我正在使用PHP和MySQL创建一个网站,当前正在处理一个处理通知的页面(例如,当某人对您的帖子发表评论时,您会收到有关该通知的通知)。 The notification is sent not as an email, but as an alert in the website when you login to your account (Facebook style). 该通知不是作为电子邮件发送,而是作为您登录帐户(Facebook风格)时网站上的警报发送。

Now my problem is in determining when to mark a notification as read. 现在,我的问题是确定何时将通知标记为已读。 In short: what is that event (such as a click, a view) that after it happens you can be sure the notification has been read, and you can change it to read? 简而言之:发生什么事件(例如单击,查看)是什么,可以确保通知已被读取,并且可以将其更改为已读?

but I already got a way around it. 但我已经解决了。 Let me just share may be it might help someone: Every alert ought to direct the user to a certain URL eg if someone commented on your post, on clicking the alert you should be directed to eg "www.example.com/posts/?post_id=5". 让我分享一下可能对某人有帮助:每个警报都应将用户定向到某个URL,例如,如果有人对您的帖子发表了评论,则在单击警报时应将您定向到“ www.example.com/posts/? post_id = 5”。 I cal this the target URL. 我将此作为目标网址。 when generating the alert, i store its target URL together with the alert details in the alerts table, and get the AI unique field(alert_id), which i will use to generate the href part of any link on the alert eg <a href="changetoread.php?alert_id=56">G Thuo</a> commented on your post. 生成警报时,我将其目标URL和警报详细信息存储在警报表中,并获取AI唯一字段(alert_id),我将使用该字段来生成警报上任何链接的href部分,例如<a href="changetoread.php?alert_id=56">G Thuo</a>对您的帖子发表了评论。 this is my approach: on clicking any alert, it first takes you somewhere where its status is changed to read(basing on the alert_id in the link). 这是我的方法:在单击任何警报时,它首先将您带到其状态更改为已读的位置(基于链接中的alert_id)。 After it's changed to read, then we fetch the target URL from the table and redirect the user there. 更改为读取后,然后我们从表中获取目标URL并在那里重定向用户。 here's my code: 这是我的代码:

$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