Google Chart Tools with PHP & MySQl
Per the docs, have you tried establishing the column references and data seperately?
var data = new google.visualization.DataTable();data.addColumn('string', 'Task');data.addColumn('number', 'Hours per Day');data.addRows([ ['Work', 11], ['Eat', 2], ['Commute', 2], ['Watch TV', 2], ['Sleep', {v:7, f:'7.000'}]]);
To format into the correct JSON for the object, you can set it up as follows:
while($r = mysql_fetch_assoc($sth)) { if(!isset($google_JSON)){ $google_JSON = "{cols: ["; $column = array_keys($r); foreach($column as $key=>$value){ $google_JSON_cols[]="{id: '".$key."', label: '".$value."'}"; } $google_JSON .= implode(",",$google_JSON_cols)."],rows: ["; } $google_JSON_rows[] = "{c:[{v: '".$r['id']."'}, {v: ".$r['quarters']."}, {v: ".$r['salary']."}]}";} // you may need to change the above into a function that loops through rows, with $r['id'] etc, referring to the fields you want to inject..echo $google_JSON.implode(",",$google_JSON_rows)."]}";
Complete Working Example: PHP/MYSQL/Google Chart/JSON