$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);
public function fetch_array()
{ return mysql_fetch_array($this->result);
//这里只返回了一行结果
}
返回是一维数组 可以通过对象读取 或者 $array=array("id"=>$row["id"]);
楼主的错误就是后面抓出的数据都把前面的覆盖了 所以最终只有一行输出哈
//print_r($a)
}
{
$result = array();
while($arr = mysql_fetch_array($this->result)){
$result[] = $arr;
}
return $result;
}
public function fetch_array(){
$resultArray = array();
while ($row = mysql_fetch_array($result))
{
array_push($resultArray,$row);
}
return $resultArray;
}
{
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()
{
$result = array();
while($arr = mysql_fetch_array($this->result))
{
array_push($result,$arr);
}
array_shift($result);
return $result;
}