neuroxik Posted March 30, 2007 Share Posted March 30, 2007 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? Quote Link to comment https://forums.phpfreaks.com/topic/44866-pushing-data-into-a-multi-dimensional-array-from-mysql-results/ Share on other sites More sharing options...
sasa Posted March 30, 2007 Share Posted March 30, 2007 try while($r=mysql_fetch_assoc($res)) array_push($chart['chart_data'][0], $r['wght']); Quote Link to comment https://forums.phpfreaks.com/topic/44866-pushing-data-into-a-multi-dimensional-array-from-mysql-results/#findComment-217944 Share on other sites More sharing options...
neuroxik Posted March 30, 2007 Author Share Posted March 30, 2007 It worked! Thanks! Thanks so much! So my only mistake was to have a 0 (zero) of too many in my array push argument? And I didn't have to assign it to the array like $chart[..]... = Quote Link to comment https://forums.phpfreaks.com/topic/44866-pushing-data-into-a-multi-dimensional-array-from-mysql-results/#findComment-217956 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.