Re: convert arrays to table

29 views
Skip to first unread message

asgallant

unread,
Aug 20, 2012, 2:14:24 PM8/20/12
to google-visua...@googlegroups.com
Do you want to do the conversion server-side or client-side?  If server-side, what language are you working in?

On Monday, August 20, 2012 12:08:09 PM UTC-4, karim wrote:
I'm new with Google chart API, I'm trying to learn and I run into a problem,

I generate an array from Mysql database at this format ,
{X, 1},{Y, 12}, {Z,23},{Y, 7},
{X, 10},{Y, 8}, {Z,3},{Y, 15}

the array should be formatted  to:
[X, 1, 10],
[Y, 12, 8],
[Z,23, 3],
[Y, 7, 15]
so I could render the data into a Bar-chart.

Does someone have an idea, how to do that, I will really appropriate it!

Thanks in advance!

-Karim

karim

unread,
Aug 20, 2012, 2:33:14 PM8/20/12
to google-visua...@googlegroups.com
Thanks a lot for taking a look to my question!
I use PHP but it should be ok if I can do it on the client-side.
Thanks again!

-Karim

asgallant

unread,
Aug 20, 2012, 4:50:47 PM8/20/12
to google-visua...@googlegroups.com
If you handle this in PHP, you can deliver it in the right format to populate the DataTable without any further work on the client-side, which makes it very handy especially if you want to implement dynamically fetching data via AJAX calls.

What, exactly, does the output from MySQL look like in terms of structure?  Is that one cell of data, 2 rows x 1 column, or 2 rows x 4 columns? Or something else entirely?

karim

unread,
Aug 20, 2012, 7:32:07 PM8/20/12
to google-visua...@googlegroups.com

I have 5 columns x (change depend on the result. ). rows

karim

unread,
Aug 20, 2012, 7:34:57 PM8/20/12
to google-visua...@googlegroups.com

it's the way around
number of  columns change depend on the result. x  4 rows
Sorry about that.

-Karim

karim

unread,
Aug 20, 2012, 10:27:32 PM8/20/12
to google-visua...@googlegroups.com
I will try to make it clear, sorry about the confusion.

If I have this array (emplyee salarry) for one month 
 ['Employee Name', 'Salarry 1st month'], ['Mike', 18,500],['Bob', 35000],['Alice', 44000], ['Fritz', 18500]

I can get this

 ['Employee Name', 'Salarry 1st month'],
  ['Mike', 18,500],
  ['Bob', 35000],
  ['Alice', 44000],
  ['Fritz', 18500]], false); 

but if I have two arrays (emplyee salarry) of two differnt months 


['Employee Name', 'Salarry 1st month ', 'Salarry 21 month '],
['Mike', 18,500], ['Mike', 18,500], 
['Bob', 35,000,], ['Bob', 44,000],
['Alice', 44,000,], ['Alice', 60,000],
['Fritz', 18500,], ['Fritz', 35,000] 

How I can get this 

 ['Employee Name', 'Salarry 1st month ', 'Salarry 21 month '],
  ['Mike', 18,500, 25,000],
  ['Bob', 35,000, 44,000],
  ['Alice', 44,000, 60,000],
  ['Fritz', 18500, 30,000]], false); 


Hope this is much clear.

Thanks!

asgallant

unread,
Aug 21, 2012, 11:38:26 AM8/21/12
to google-visua...@googlegroups.com
What I'm trying to get at is the data returned from the SQL query.  What does an example table layout of the results look like?
Reply all
Reply to author
Forward
0 new messages