我怎么能回应最后的记录php mysql

时间:2018-04-02 07:50:54

标签: php mysql

对于项目,需要回显最后4个数据库记录。我有一个脚本显示所有记录,但我只需要最后一个4.有人可以帮我吗?

<?php
$con = mysql_connect("localhost","test","test");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }

mysql_select_db("test", $con);

$result = mysql_query("SELECT * FROM formulier");

echo "<table border='1'>
<tr>
<th>tafel</th>

</tr>";

while($row = mysql_fetch_array($result))
  {
  echo "<tr>";
  echo "<td>" . $row['tafel'] . "</td>";

  echo "</tr>";
  }
echo "</table>";

mysql_close($con);
?>

谢谢!

1 个答案:

答案 0 :(得分:1)

尝试此查询... SELECT * FROM your_dataBase ORDER BY id DESC LIMIT 4