Jump to content

Pushing data into a multi-dimensional array from mysql results


neuroxik

Recommended Posts

Hey everyone, I've sweated over this last night and hope somebody could help me out.

 

First, A result array I'd want to get could look like this:

 

$chart['chart_data'] = array ( 
array ( "Region A", 10,12,11,15,20,22,21,25,31,32,),
);

 

The first is "Region A" and the rest is just int's that I'd pull from the db, so to set it I'd do this:

 

$chart [ 'chart_data' ][ 0 ][ 0 ] = "Region A";

 

But the problem is when I want to insert the data in the while loop (like the 10,12,11,15...), I've tried array_push but it's not working, maybe it doesn't work with multi-dimensional arrays? Anyways, here.'s what I tried, the following inside the "while" to loop the mysql results with mysql_fetch_assoc:

 

while($r=mysql_fetch_assoc($res)) {
    
     $chart [ 'chart_data' ][ 0 ][ 0 ] = array_push($chart['chart_data'][0][0], $r['wght']);
     // the above line is where I have problems    ^^
}

 

What I want is on each loop to insert the fetched data inside the array so that it gives what I gave first at the top, but what I've written above doesn't work, it gives me a warning saying "first argument must be an array" which seems to be one, but anyway, anybody know how to do this?

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.