$sql="select * from admin ";
$result = mysql_query($sql);
while($arr = mysql_fetch_array($result) ){
...
}能从数据库读取 正常数据,但是用类操作 竟然只有一个一维数组:(类的代码如下)public function query($sql)
{
if($sql == ""){
$this->show_error("sql语句错误:","sql查询语句为空");} 
     $this->sql = $sql; 
    
     $result = mysql_query($this->sql,$this->conn); 
    
if(!$result){

if($this->show_error){
$this->show_error("错误sql语句:",$this->sql);
}
}else{
$this->result = $result; 
}
     return $this->result;    
}public function fetch_array()  
{
return mysql_fetch_array($this->result); 
}我的代码:
$sql="select * from admin ";
$a=$db->fetch_array($db->query($sql));
print_r($a);

解决方案 »

  1.   

    ...楼主 你还是多看看手册吧!mysql_fetch_array — 从结果集中取得一行作为关联数组,或数字数组,或二者兼有 
      

  2.   


       public function fetch_array()  
        {                return mysql_fetch_array($this->result); 
            //这里只返回了一行结果
        }
      

  3.   

    mysql_fetch_array($this->result); 
    返回是一维数组 可以通过对象读取 或者 $array=array("id"=>$row["id"]);
      

  4.   

    mysql_fetch_array mysql_fetch_row 其实是一样的 区别就在于key值不一样
    楼主的错误就是后面抓出的数据都把前面的覆盖了 所以最终只有一行输出哈
      

  5.   

    while($a = mysql_fetch_array($sql)){
    //print_r($a)
    }
      

  6.   

    public function fetch_array()  
        {        
    $result = array();
            while($arr = mysql_fetch_array($this->result)){
    $result[] = $arr;
    }
    return $result;
        }
      

  7.   

    while($db->fetch_array($db->query($sql)));
      

  8.   


    public function fetch_array(){
            $resultArray = array();
            while ($row = mysql_fetch_array($result)) 
            {
                array_push($resultArray,$row);
            }
            return $resultArray;
    }
      

  9.   

    这里错了!public function query($sql)
        {        
            if($sql == ""){
            $this->show_error("sql语句错误:","sql查询语句为空");} 
            $this->sql = $sql; 
            
            $result = mysql_query($this->sql,$this->conn); 
        
            if(!$result){
                
                if($this->show_error){
                    $this->show_error("错误sql语句:",$this->sql);
                }
            }else{
                $this->result = $result; 
            }
            return $this->result;       
        }
      

  10.   


    public function fetch_array()  
    {        
       $result = array();
       while($arr = mysql_fetch_array($this->result))
      {
         array_push($result,$arr);
       }
      array_shift($result);
      return $result;
    }