Reputation: 182
So I'm trying to only select the last ten posts from the database. I had this code to select everything:
$sql=mysql_query("SELECT * FROM posts ORDER BY PostID DESC");
while ($row = mysql_fetch_array($sql, MYSQL_BOTH)) {
....
}
But when I tried to select the last 10 with this code:
$sql=mysql_query("SELECT TOP 10 * FROM posts ORDER BY PostID DESC");
while ($row = mysql_fetch_array($sql, MYSQL_BOTH)) {
....
}
...it doesn't work.
I get this error: mysql_fetch_array(): supplied argument is not a valid MySQL result resource
What's up?
Upvotes: 0
Views: 127
Reputation: 14428
Try this:
$sql=mysql_query("SELECT * FROM posts ORDER BY PostID DESC LIMIT 0, 10");
Upvotes: 8