doulechou0700 2011-12-09 21:05
浏览 59
已采纳

一个php预定义变量,用于处理从SQL查询返回的多维数组

after these for example

$result = mysql_query("SELECT id, name FROM mytable")

i tried to echo back this

$row=mysql_fetch_array($results, MYSQL_ASSOC);

when i did run the query in my PHPmyadmin SQL command it came back with several lines in columns (three) from the table but when i echo back $row it give back just one line

<?php echo print_r($row); ?> 
  • 写回答

1条回答 默认 最新

  • dongwuqi4243 2011-12-09 21:06
    关注

    You need to continuously call mysql_fetch_array() until it returns false, as the function returns the current row and moves the internal pointer ahead. A return value of false means you have iterated through all the rows:

    while($row = mysql_fetch_array($results, MYSQL_ASSOC))
    {
        // do something with $row
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 如何使用canvas在图片上进行如下的标注,以下代码不起作用,如何修改
  • ¥15 Windows 系统cmd后提示“加载用户设置时遇到错误”
  • ¥50 vue router 动态路由问题
  • ¥15 关于#.net#的问题:End Function
  • ¥15 无法import pycausal
  • ¥15 VS2022创建MVC framework提示:预安装的程序包具有对缺少的注册表值的引用
  • ¥15 weditor无法连接模拟器Local server not started, start with?
  • ¥20 6-3 String类定义
  • ¥15 嵌入式--定时器使用
  • ¥20 51单片机学习中的问题