PHP - While循环不显示表记录

时间:2015-08-17 09:22:45

标签: php

在下面的代码中,它显示了循环外的表行值但是在循环中没有显示。虽然循环不起作用;请让我知道它有什么不对吗?

<?php
      $sql = "SELECT * FROM cl_banner ORDER BY id;";
      $res = q($sql) or die(mysql_error());
      if($res && mysql_num_rows($res)>0)
      { 
          while($row = mysql_fetch_assoc($res));
          { 
             echo $row["title"]; 
             echo "hi";
          } // End While
       } // End If                      
?>

2 个答案:

答案 0 :(得分:0)

<?php
        $sql = "SELECT * FROM cl_banner ORDER BY id";
                                                 ^^^^
        $res = mysql_query($sql) or die(mysql_error()); 
              ^^^^^^^^^^ 
        if($res && mysql_num_rows($res)>0)
            {   
                while($row = mysql_fetch_assoc($res));
                {   
                    echo $row["title"]; 
                    echo "hi";
                } // End While
            } // End If                     
    ?>

答案 1 :(得分:0)

试试这个:

<?php
  $sql = "SELECT * FROM cl_banner ORDER BY id";
  $res = mysql_query($sql) or die(mysql_error());
  if($res && mysql_num_rows($res)>0)
  { 
      while($row = mysql_fetch_assoc($res))
      { 
         echo $row["title"]; 
         echo "hi";
      } // End While
   } // End If                      
?>