找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索本站精品资源

首页 教程频道 php教程 查看内容

为何mysql_fetch_array/assoc+foreach只能遍历一条记录

作者:模板之家 2020-3-29 12:34 168人关注

为什么mysql_fetch_array/assoc+foreach只能遍历一条记录foreach(mysql_fetch_array($result)as$key=$row){print_r($row);,为何mysql_fetch_array/assoc+foreach只能遍历一条记录

为什么mysql_fetch_array/assoc + foreach只能遍历一条记录
foreach(mysql_fetch_array($result) as $key=>$row){

  print_r($row);



这样只能遍历输出最后一条记录

下面这样就能全部遍历,是不是说明数据库返回的数组与平常的不同?

while($row=mysql_fetch_array($result)) 

       $rows[]  = $row; 


foreach($rows as $k => $v) 

   foreach($v as $vv){
     echo $vv;
   }
mysql_fetch_array ?foreach

------解决方案--------------------
while 可以循环读取数据库中的记录,而foreach 只能遍历已存在的数组或者对象。

路过

雷人

握手

鲜花

鸡蛋
原作者: 互联网 来自: 网络收集

全部回复(0)