0

In the code below, I get the 9 latest objects in the table. Of this 9 objects, the last is presented as the latest. I wonder if it's possible to get the oppesite. Of this 9 objects, that the latest is the first in the result!? I hope my question isn't unclear!? It's hard to explain!

$query2 = "SELECT * from buildingObjects WHERE id > (SELECT MAX(id) - 9 FROM arkitekturobjekt)";
$result = $mysqli->query($query2);
while($row = $result->fetch_object()) {
// Show the objects here
}
4

2 回答 2

2

If you are only interested in the last 9 IDs, listed last to first, you could simply do:

SELECT * FROM buildingObjects ORDER BY id DESC LIMIT 9
于 2013-06-12T19:36:00.543 回答
0

If id is an auto_increment primary key index you can go for ORDER BY id DESC, still if you are also storing dates or date and time, you could go for the date field order instead.

于 2013-06-12T20:05:17.980 回答