SQL排序堆叠


SQL ordering stacking

我有这个:http://screencloud.net/img/screenshots/e796a906e816a8c44f9be15ed37d1735.png

可以看出,在右边,它和左边显示的顺序是一样的。我不想让它显示出来。我希望在我发布新闻文章时,它会堆叠在一起,但在左边显示最老的。如果你明白我的意思。

我不想要这个:http://screencloud.net/img/screenshots/d9be1bd327b31c523094e19510ff4922.png

,如果视图向右看,他们看到的是同一篇文章。整篇文章左边的代码是这样的:

$grab = mysql_query("SELECT * FROM articles WHERE id='" . mysql_real_escape_string($_GET['id']) . "' LIMIT 1");    
$grab = mysql_query("SELECT id, news_title, news_content, news_author, news_day, news_month, news_year, news_date FROM articles ORDER BY id DESC limit 4"); 

右边的是:

$grab = mysql_query("SELECT id, news_title, news_content, news_author, news_day, news_month, news_year, news_date FROM articles ORDER BY id DESC limit 8");

你们知道我做错了什么吗?

我相信你正在寻找MySQL的OFFSET关键字:

SELECT id, news_title, news_content, news_author, news_day, news_month, news_year, news_date FROM articles ORDER BY id DESC limit 8 offset 4

或者更简单:

SELECT id, news_title, news_content, news_author, news_day, news_month, news_year, news_date FROM articles ORDER BY id DESC limit 4,8
http://dev.mysql.com/doc/refman/5.0/en/select.html

试试这个LIVE DEMO: http://sqlfiddle.com/#!2/0a05db/8

使用LIMIT X,Y与X =开始#的行和Y =行数…