[英]MySQL timestamp comparison with less than sign
我做了一个PHP博客。 除了一个小故障外,一切都正常运行。 我想按日期按降序显示文章。 因此,无论何时将文章添加到数据库,自动时间戳都会记录插入时间。
GLITCH - >我想每页显示5篇文章。 我通过使用它在第一页轻松地做到了
$sql="SELECT id,article_name,article_body,date
from articles order by date desc limit 5" ;
现在我想继续第二页,并希望第二页显示第1页离开的文章。 如果有10篇文章按降序排列,则第1页应显示前5个,第2页应显示下5个。
当每天添加许多文章时,此逻辑应该实时工作。 我使用了这个查询,但它只显示了一行。
$sql="select id,article_name,article_body,unix_timestamp(date)
from articles
where date < (select unix_timestamp(date)
from articles order by date desc limit $n,1 )
order by date desc limit $n,5" ;
$ n - 提取行的ID。
利用sql中的偏移量:
$items_per_page=5;
$offset=($current_page-1)* $items_per_page;
sql:
SELECT id,article_name,article_body,date
from articles order by date desc LIMIT $items_per_page OFFSET $offset
尝试:
select id,article_name,article_body,unix_timestamp(date)
from articles
where date < ( select date from articles order by date desc limit $n,1 )
order by date desc limit $n,5
其中$ n应该是上一页的最后一个id
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.