include_once('conn.php');$sql=sprintf("select data from dt where id='1'");$result=mysql_query($sql,$conn);
while($row=mysql_fetch_array($result))
{$z=$row['data'];}
mysql_close($conn);
当只有一个数据时,而不是多个数据时,要while读取吗?好像不要吧。怎么改才好?

解决方案 »

  1.   

    如果能确定是只有一条,直接
    $row=mysql_fetch_array($result)
    不是就可以了么。
      

  2.   

    mysql_fetch_row()其实是一样的,只不过一般时候数据比较多吧!
      

  3.   

    include_once('conn.php');
    $sql=sprintf("select data from dt where id='1'");
    $result=mysql_query($sql,$conn);
    $row=mysql_fetch_array($result);
    $z=$row['data']; 
    mysql_close($conn);
      

  4.   

    while 读取是比较好的,万一你的数据库没有取出来记录,你直接写mysql_fetch_array()是会出现问题的,while 避免了这样的问题
      

  5.   


    支持,while多了一道判断,不用循环就用if判断吧