array
(
[0]=>3
[1]=>59
[2]=>23
[3]=>4
[4]=>61
)
.... $data = array(); if (!$error=$this->query($sql)) { $results = array(); while (!($error=$this->fetcharray($results))) { $data[] = $results; } } $this->free(); return $data;....
回复讨论(解决方案) 你那段 php 代码是什么意思?
你那段 php 代码是什么意思?
从数据库里读取数据
public getinfo(){ $sql=select * from table; $result=$this->db->getallone($sql); return $result;}
function getallone($sql) { $data = array(); if (!$error=$this->query($sql)) { $results = array(); while (!($error=$this->fetcharray($results))) { $data[] = $results; } } $this->free(); return $data; }
那你贴图中的数据是从哪里得到的?
那你贴图中的数据是从哪里得到的?
从数据库读取的
读取出来时是array嵌套array
我想要的是array里直接是我想要的值 (只查询表里的一个字段)
所以要修改下面函数
function getallone($sql) { $data = array(); if (!$error=$this->query($sql)) { $results = array(); while (!($error=$this->fetcharray($results))) { $data[] = $results; } } $this->free(); return $data; }
问题是:
$results = array(); //这是一个空数组
while (!($error=$this->fetcharray($results))) {
$data[] = $results; //你把一个空数组赋值给 $data[],怎么会有截图中的数据呢?
}
问题是:
$results = array(); //这是一个空数组
while (!($error=$this->fetcharray($results))) {
$data[] = $results; //你把一个空数组赋值给 $data[],怎么会有截图中的数据呢?
}
我的错
fetcharray() 是自定义函数,
