SQL排序堆叠

时间:2013-03-04 00:28:53

标签: php html

我有这个: 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");
你会碰巧知道我做错了什么吗?

2 个答案:

答案 0 :(得分:0)

我相信您正在寻找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

答案 1 :(得分:0)

试试这个现场演示:http://sqlfiddle.com/#!2/0a05db/8

使用LIMIT X,Y,其中X =起始行#和Y =行数...