php?mysql

WBOY
Release: 2016-06-20 12:43:35
Original
908 people have browsed it


想要的返回结果:
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;....
Copy after login


回复讨论(解决方案)

你那段 php 代码是什么意思?

你那段 php 代码是什么意思?


从数据库里读取数据
public getInfo(){     $sql="select * from table";     $result=$this->db->getAllone($sql);     return $result;}
Copy after login

function getAllone($sql) {        $data = array();        if (!$error=$this->query($sql)) {            $results = array();            while (!($error=$this->fetchArray($results))) {                $data[] = $results;            }        }        $this->free();        return $data;    }
Copy after login
Copy after login

那你贴图中的数据是从哪里得到的?

那你贴图中的数据是从哪里得到的?



从数据库读取的
读取出来时是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;    }
Copy after login
Copy after login

问题是:
            $results = array(); //这是一个空数组
            while (!($error=$this->fetchArray($results))) {
                $data[] = $results; //你把一个空数组赋值给 $data[],怎么会有截图中的数据呢?
            }

问题是:
            $results = array(); //这是一个空数组
            while (!($error=$this->fetchArray($results))) {
                $data[] = $results; //你把一个空数组赋值给 $data[],怎么会有截图中的数据呢?
            }



我的错
fetchArray() 是自定义函数,
Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template