我试图找到一个解决方案,使我的PHP脚本只显示最后3条,但我能找到的是如何显示第一个条目不是最后3.任何想法?我怎样才能只显示最后3行?
这是显示的条目脚本:
<?php
// Grab the data from our people table
$sql = "select * from people";
$result = mysql_query($sql) or die ("Could not access DB: " . mysql_error());
while ($row = mysql_fetch_assoc($result)) {
echo "<div class=\"picture\">";
echo "<p>";
// Note that we are building our src string using the filename from the database
echo "<img src=\"content/uploads/" . $row['filename'] . "\" alt=\"\" /><br />";
echo $row['fname'] . " " . "<br />" . "<br />" . $row['lname'] . "<br />";
echo "</p>";
echo "</div>";
}
?>
只是做反向'ORDER BY' – Legionar 2014-11-06 10:00:14
只要使用正确的查询关键词,比如'SELECT * FROM人ORDER BY ID DESC LIMIT 3'通过primary_key给你的主键'id' – kero 2014-11-06 10:00:22
'SELECT * FROM人为了desc限制3',其中主键是从你的表 – 2014-11-06 10:00:23