Home  >  Article  >  Backend Development  >  php?mysql

php?mysql

WBOY
WBOYOriginal
2016-06-20 12:43:35826browse


想要的返回结果:
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() 是自定义函数,
Statement:
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