doubao6681 2014-10-30 09:52
浏览 62
已采纳

GROUP_CONCAT查询中的var_dump无法正常工作

I'm trying to print a value from a group_concat query, but for some reason, the code keeps failing. If I print the array that contains my value, I am able to see that everything is being fetched correctly. But when I try to access the first element in the array, my page gives me a white screen. Why is this happening?

$db =& JFactory::getDBO();
 $db->setQuery("SELECT GROUP_CONCAT( FieldValue )
FROM tpro_rsform_submission_values
WHERE FieldName
IN (
'LAST NAME', 'FIRST NAME'
)
GROUP BY SubmissionId");

$result = $db->loadObjectList();
foreach ($result as $r) {
        echo var_dump($r);
}
// </code>

The following is the result for my var_dump($r)

enter image description here but when I try to do a var_dump($r[0]), my page gives me a white screen.

Similarly, when I try to access the field through var_dump($r['GROUP_CONCAT(FieldValue)']) I still get a white screen. How do can we access the field?

  • 写回答

2条回答 默认 最新

  • duanbeng8872 2014-10-30 10:00
    关注

    You need to give the field an alias -

    $db->setQuery("SELECT GROUP_CONCAT( FieldValue ) AS whatever
    

    and then

    echo var_dump($r->whatever);
    

    I am not sure why you're using $result = $db->loadObjectList(); though. You could use any of the array methods and it would be better/easier for what you're trying to do. Then you would say:

    echo var_dump($r['whatever']);
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)
编辑
预览

报告相同问题?

悬赏问题

  • ¥15 QGC打开没有地图显示,离线地图也不显示,如何解决?
  • ¥20 Android Studio 的 webview 与访问网络存在的限制
  • ¥15 某帖子的数据集不清楚来源,求帮助
  • ¥50 tc358743xbg寄存器配置
  • ¥15 idea构建mod报错无效的源发行版项目链接,如何解决?
  • ¥15 springboot中的路径问题
  • ¥80 App Store Connect 中设置了订阅项目,Xcode 中预览可以正确显示价格,真机测试却无法显示
  • ¥15 MATLAB的PIV算法问题
  • ¥15 RflySim例程学习:matlab编译报错
  • ¥20 谁来给我解答一下疑惑
手机看
程序员都在用的中文IT技术交流社区

程序员都在用的中文IT技术交流社区

专业的中文 IT 技术社区,与千万技术人共成长

专业的中文 IT 技术社区,与千万技术人共成长

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

客服 返回
顶部