2013-03-04 131 views
0

我有這樣的: http://screencloud.net/img/screenshots/e796a906e816a8c44f9be15ed37d1735.pngSQL順序堆疊

正如你所知道的,在右邊,它顯示了相同的順序,它在左邊。我不想讓它基本顯示出來。我希望它在哪裏,因爲我發佈新聞文章,它會堆疊,但顯示在左邊最古老。如果你明白我的意思。

我不希望這樣的: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"); 

將你們碰巧知道它是什麼,我做錯了?

+0

[**請不要在新代碼中使用'mysql_ *'函數**](http://bit.ly/phpmsql)。他們不再被維護[並且被正式棄用](http://j.mp/XqV7Lp)。看到[**紅框**](http://j.mp/Te9zIL)?學習[*準備的語句*](http://j.mp/T9hLWi),並使用[PDO](http://php.net/pdo)或[MySQLi](http://php.net/ mysqli) - [這篇文章](http://j.mp/QEx8IB)將幫助你決定哪個。 – Kermit 2013-03-04 00:30:24

+0

我還添加了「ASC」,但它保留在數據庫中最古老的文章中,並且不移動。 – TrippedStackers 2013-03-04 00:30:59

+0

@TrippedStackers你想要它嗎?剩下什麼,什麼是對的? – michi 2013-03-04 00:33:13

回答

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