我想从SQL表中选择前50行,并将它们显示为最新到最旧的

时间:2012-11-21 11:20:37

标签: php sql

    <?php
mysql_select_db("mgshuheb") or die("No such database");
$str = "SELECT * FROM posts ORDER BY id DESC";
$rs = mysql_query($str);
while($row = mysql_fetch_array($rs)) {

      echo '<span class="name">' . $row["name"] . '</span>'."<br />";
      echo $row["post"] . "<br />";
      echo $row["time"] . "<br /><br />";
      }
?>

这是我现在所拥有的。当我输入SELECT TOP 50 * FROM posts ORDER BY id DESC;时,它会不断出现错误。

2 个答案:

答案 0 :(得分:3)

在MySQL中,使用limit代替top

SELECT  * 
FROM    posts 
ORDER BY 
        id DESC
LIMIT   50

答案 1 :(得分:0)

您必须对查询设置限制

<?php
    $str = "SELECT * FROM posts ORDER BY id DESC LIMIT 0,50";
 ?>