Home > Backend Development > PHP Tutorial > 使用mysql_fetch_array()总是没结果

使用mysql_fetch_array()总是没结果

WBOY
Release: 2016-06-06 20:16:09
Original
980 people have browsed it

<code>  代码如下:
    if (!$con)
      {die('Could not connect: ' . mysql_error());}
      else{ echo  "nice"."<br>";}
      
    mysql_select_db("test", $con); echo"get the databse"."<br>";
    
      $result =mysql_query("select * from hat_province");echo"get the table"."<br>";
      
    while($row = mysql_fetch_array($result))
      {
      echo $row['id'] . " " . $row['province'];
      echo "<br>";
      }
      
     在while($row = mysql_fetch_array($result))这里总是停住出不了结果,请问到底为什么出不了结果</code>
Copy after login
Copy after login

回复内容:

<code>  代码如下:
    if (!$con)
      {die('Could not connect: ' . mysql_error());}
      else{ echo  "nice"."<br>";}
      
    mysql_select_db("test", $con); echo"get the databse"."<br>";
    
      $result =mysql_query("select * from hat_province");echo"get the table"."<br>";
      
    while($row = mysql_fetch_array($result))
      {
      echo $row['id'] . " " . $row['province'];
      echo "<br>";
      }
      
     在while($row = mysql_fetch_array($result))这里总是停住出不了结果,请问到底为什么出不了结果</code>
Copy after login
Copy after login

确认你的数据库链接正常后,将while循环放到

<code>if($result){
    while(){
        
    }
}else{
    exit('have no data!');
}</code>
Copy after login

调试下,看为什么停住,应该很容易调试出来问题的。

用pdo或者mysqli吧,别再用mysql_开头的函数了

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template