我試圖找到一個解決方案,使我的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