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

我这个只想要键值不想要键名 应该怎么弄?

2024/2/28 14:38:49发布17次查看
query('select * from blog');
 $result = $sth->fetchall(pdo::fetch_assoc);
 foreach($result as $v){
    print_r($v);
}
?>
回复讨论(解决方案) 用fetch_row(),重新建建一个数组,将查到的内容装到新数组里,这样就没原来的键值名了
$rows = array();//建立一个数组用来装查询结果
while($row = $result->fetch_row()){//只要能查到结果就执行
    $rows[] = $row;//将每次查的结果装到之前定义的数组
}
$pdo=new pdo(mysql:host=localhost;dbname=mysql,root,);$sth=$pdo->query('select * from user');$result = $sth->fetchall(pdo::fetch_assoc);$tmp_ary=array();foreach($result as $v){ $tmp_ary[]=array_values($v);}echo '';print_r($tmp_ary);echo '


';
用fetch_row(),重新建建一个数组,将查到的内容装到新数组里,这样就没原来的键值名了
$rows = array();//建立一个数组用来装查询结果
while($row = $result->fetch_row()){//只要能查到结果就执行
$rows[] = $row;//将每次查的结果装到之前定义的数组
}
提示错误 是怎么回事?
fatal error: call to a member function fetch_row() on a non-object in d:\wamp\www\cxblog2.php on line 9
$pdo=new pdo(mysql:host=localhost;dbname=mysql,root,);$sth=$pdo->query('select * from user');$result = $sth->fetchall(pdo::fetch_assoc);$tmp_ary=array();foreach($result as $v){ $tmp_ary[]=array_values($v);}echo '';print_r($tmp_ary);echo '


';
这打印出来的还是一个数组啊
$pdo=new pdo(mysql:host=localhost;dbname=mysql,root,);$sth=$pdo->query('select * from user');$result = $sth->fetchall(pdo::fetch_assoc);$tmp_ary=array();foreach($result as $v){ $tmp_ary[]=array_values($v);}echo '';print_r($tmp_ary);echo '


';
这样打印出来还是有键名啊 参数 pdo::fetch_assoc 返回关联键数组,键名为列名
参数 pdo::fetch_num 返回下标数组,下标从 0 开始
fetch 和 fetchall 总是返回数组,因为 php 不能预知查询结果有几列(不对 sql 指令做语法分析)
用fetch_row(),重新建建一个数组,将查到的内容装到新数组里,这样就没原来的键值名了
$rows = array();//建立一个数组用来装查询结果
while($row = $result->fetch_row()){//只要能查到结果就执行
    $rows[] = $row;//将每次查的结果装到之前定义的数组
}
提示错误 是怎么回事?
 fatal error: call to a member function fetch_row() on a non-object in d:\wamp\www\cxblog2.php on line 9
你的sql查询语句是什么,可能你查出来的$result不是一个对象
该用户其它信息

VIP推荐

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