您好,欢迎来到三六零分类信息网!老站,搜索引擎当天收录,欢迎发信息
三六零分类信息网 > 佛山分类信息网,免费分类信息发布

php?mysql

2026/1/20 1:40:00发布16次查看
想要的返回结果:
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() 是自定义函数,
佛山分类信息网,免费分类信息发布

VIP推荐

免费发布信息,免费发布B2B信息网站平台 - 三六零分类信息网 沪ICP备09012988号-2
企业名录 Product