Reputation: 97
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?
Upvotes: 0
Views: 58
Reputation: 1949
You may use GROUP_CONCAT(expr) function.
The query would look something like:
SELECT
names,
GROUP_CONACT( CONCAT( file_names, ",", value ) SEPARATOR "|")
FROM
myTable
Upvotes: 1