doubi1910 2014-04-03 10:18
浏览 36

php mysql查询根据名称返回结果

I have a mysql table that consists of names, file names and a value. The file name and value are always different. Is it possible to query mysql from php to output the result as a single name and the matching file names and values? The reason for this is I need to create a stacked bar chart using pchart. So I need the names for the axis and the values for the chart data. The structure of the table:

name | file | value
jack | file1.txt | 10
jack | file2.txt | 2
jack | file4.txt | 73

Output wanted:

array( [Jack] => file1.txt, 10
                 file2.txt, 2
                 file3.txt, 73
      )

Currently I'm able to get all the data with a normal query and while loop. How would I do this?

  • 写回答

1条回答 默认 最新

  • dragon7713 2014-04-03 10:26
    关注

    You may use GROUP_CONCAT(expr) function.

    The query would look something like:

    SELECT
        names,
        GROUP_CONACT( CONCAT( file_names, ",", value ) SEPARATOR "|")
    FROM
        myTable
    
    评论

报告相同问题?

悬赏问题

  • ¥15 stm32开发clion时遇到的编译问题
  • ¥15 lna设计 源简并电感型共源放大器
  • ¥15 如何用Labview在myRIO上做LCD显示?(语言-开发语言)
  • ¥15 Vue3地图和异步函数使用
  • ¥15 C++ yoloV5改写遇到的问题
  • ¥20 win11修改中文用户名路径
  • ¥15 win2012磁盘空间不足,c盘正常,d盘无法写入
  • ¥15 用土力学知识进行土坡稳定性分析与挡土墙设计
  • ¥70 PlayWright在Java上连接CDP关联本地Chrome启动失败,貌似是Windows端口转发问题
  • ¥15 帮我写一个c++工程