我正在尝试从 MySQL 数据库检索上次查看的页面,其结构如下:
文章表
id | title | content | created
----------------------------------------
1 | title-1 | info-1 | 1386478352
2 | title-2 | info-2 | 1386532855
3 | title-3 | info-3 | 1386637325
4 | title-4 | info-4 | 1386812249
5 | title-5 | info-5 | 1387094028
我想获取最后查看的页面,不确定需要多少时间,因为每次刷新网站上的页面时都会调用此函数..但是,这是我尝试过的,但它没有返回任何内容。
"SELECT * FROM articles WHERE TIMESTAMPDIFF(MINUTE, created,NOW()) < 10 LIMIT 2"
但正如我所说,它不返回任何数据。这就是我尝试打印信息的方式。
$loopOne = 0;
foreach($articleLastView as $recent)
{
$recent_id = $recent['id'];
$recent_title = $recent['title'];
$recent_created = $recent['created'];
if ( $loopOne == 0 )
{
echo 'I print info here if result is the first';
$loopOne++;
}
else if( $loopOne == 1 )
{
echo 'I print info here if result is the second';
$loopOne++;
}
}
最佳答案
"SELECT * FROM `articles` ORDER BY `created` DESC LIMIT 1"
这应该获取最后查看的页面。
关于php - 从 MySQL 时间戳获取上次查看的项目,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21057487/