0

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?

2
  • Could you elaborate the question more. if possible give the mysql table structure with sample data Commented Apr 3, 2014 at 11:27
  • @Ragavendran Ramesh - Just edited the question Commented Apr 4, 2014 at 4:45

1 Answer 1

1

You may use GROUP_CONCAT(expr) function.

The query would look something like:

SELECT
    names,
    GROUP_CONACT( CONCAT( file_names, ",", value ) SEPARATOR "|")
FROM
    myTable
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks for the response. Working through the notes from the link. Not getting the data output as I wan it but I'm a step further. Thanks Again

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.