我正在嘗試從MySQL數據庫,其構造爲跟着過去看頁面觀看項:獲得最後從MySQL時間戳
articles table
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++;
}
}
也許我失去了一些東西,但列'created'是如何與最後一次觀看的時間?我會想象該字段將包含文章創建時間的時間戳... – jeroen
您提供的數據的期望結果是什麼? –