我想输出最新四条,用while循环输出,但是实际输出了N条,而且数据库只有一条,它就循环输出了N次,网页差点就打不开,应该怎么逐条输出查询出来的内容,有几条输出几条<?php
          $str="select name,time,title,comment from comment order by time desc limit 0,4";
  $result=mysql_query($str);
  $row = mysql_fetch_array($result);
  if(!$row){
?>
        <p>There is no comment!</p>
        <?php
  }
  else{
while($row){
              echo $row['name']."于".$row['time']."发表:<br/>";
  echo $row['title']."<br/>";
  echo $row['comment']."<br/>";
}
  }
?>

解决方案 »

  1.   


    <?php
              $str="select name,time,title,comment from comment order by time desc limit 0,4";
              $result=mysql_query($str);
              $row = mysql_fetch_array($result);
              if(!$row){
            ?>
            <p>There is no comment!</p>
            <?php
              }
              else{
                while($row){
                  echo $row['name']."于".$row['time']."发表:<br/>";
                  echo $row['title']."<br/>";
                  echo $row['comment']."<br/>";
                  $row = mysql_fetch_array($result);
                }
              }
            ?>
      

  2.   

    while($row)中的条件是需要有改变机制的,一直触发不了改变就会死循环。
      

  3.   

    <?php
    $str="select name,time,title,comment from comment order by time desc limit 0,4";
    $result=mysql_query($str);
    $row = mysql_fetch_array($result);
    if(!$row){
    ?>
    <p>There is no comment!</p>
    <?php
    }
    else{
    while($row = mysql_fetch_array($result)){                                 // changed by ACMAIN
    echo $row['name']."于".$row['time']."发表:<br/>";
    echo $row['title']."<br/>";
    echo $row['comment']."<br/>";
    }
    }
    ?>