drd2551 2015-07-09 11:22
浏览 65
已采纳

在php中循环结果集

I am new to php and i am using PDO for db operations

through a query i get the result set which is printed using print_r() function

Output looks like

Array
(
[0] => Array
    (
        [selection_id] => 8947562
        [price_difference] => 1.02
        [one_miniute_price] => 4.20
        [one_min_pc] => 0.2381
    )

[1] => Array
    (
        [selection_id] => 8801685
        [price_difference] => 1.00
        [one_miniute_price] => 13.50
        [one_min_pc] => 0.0741
    )

[2] => Array
    (
        [selection_id] => 9464307
        [price_difference] => 1.00
        [one_miniute_price] => 11.00
        [one_min_pc] => 0.0909
    )

[3] => Array
    (
        [selection_id] => 9066075
        [price_difference] => 0.99
        [one_miniute_price] => 1.99
        [one_min_pc] => 0.5025
    )

[4] => Array
    (
        [selection_id] => 8726674
        [price_difference] => 0.95
        [one_miniute_price] => 10.50
        [one_min_pc] => 0.0952
    )

)

Now my problem is that i want to loop though this output and access the columns for each record

Any help is highly appreciated

regards

  • 写回答

4条回答 默认 最新

  • dougao1542 2015-07-09 11:28
    关注
    foreach($array as $result) {
        echo $result["selection_id"];
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)

报告相同问题?

悬赏问题

  • ¥15 R语言Rstudio突然无法启动
  • ¥15 关于#matlab#的问题:提取2个图像的变量作为另外一个图像像元的移动量,计算新的位置创建新的图像并提取第二个图像的变量到新的图像
  • ¥15 改算法,照着压缩包里边,参考其他代码封装的格式 写到main函数里
  • ¥15 用windows做服务的同志有吗
  • ¥60 求一个简单的网页(标签-安全|关键词-上传)
  • ¥35 lstm时间序列共享单车预测,loss值优化,参数优化算法
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值