每次用户阅读帖子时,它都会分配一个 cookie,例如。
set_cookies($id,'read',60*60*24);
但问题是我如何选择所有用户尚未阅读的帖子?
SELECT * from posts where (post is unread)
它不需要登录。表结构:
ID | Content | Category
最佳答案
使用您的解决方案,您将执行以下操作:
$ids = array();
if (isset($_COOKIES)) {
foreach ($_COOKIES as $cookie => $value) {
if (is_numeric($cookie) && $value == 'read') {
$ids[] = $cookie;
}
}
}
if (isset($ids[0])) {
$posts = implode(',',$ids);
$query = "SELECT * from posts where id in ({$posts})";
// Do the query
} else {
// no read posts.
}
但是您确实应该考虑以不同的方式存储读取的变量。
关于php - 在数据库中搜索未读帖子,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8582556/