首頁  >  文章  >  後端開發  >  php?mysql

php?mysql

WBOY
WBOY原創
2016-06-20 12:43:35826瀏覽


想要的返回结果:
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() 是自定义函数,
陳述:
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn