i'm having a problem with getting data to the JSON format.
then i put it in an JSONTable with JSON_ENCODE. But i only get the first parameter of my mysql Table
<?php
$q=$_GET["q"];
$con = mysql_connect("xxxxxxxxx","xxxxxx","xxxxxxxxxx");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
//DB selecteren
mysql_select_db("emOs", $con);
//data vn de db krijgen
$result = mysql_query("SELECT datum, opbrengst FROM `dagenvandeweek`;") or die(mysql_error());
$rows = array();
$table = array();
$table['cols']=array(
array('label'=>'datum', 'type'=> 'string'),
array('label'=>'opbrengst', 'type'=> 'number')
);
while($r = mysql_fetch_assoc($result))
{
$temp[] = array('v' => (string) $r['datum']);
$temp[] = array('v' => (int) $r['opbrengst']);
$rows[] = array('c' => $temp);
}
$table['rows'] = $rows;
$jsonTable = json_encode($table);
echo $jsonTable;
/*echo '<h1> TABLE </h1>';
displayArray($table);
echo '<h1> TEMP </h1>';
displayArray($temp);
echo '<h1> ROWS </h1>';
displayArray($rows);*/
function displayArray($val)
{
echo "<pre>";
print_r($val);
echo "</pre>";
return;
}
mysql_close($con);
?>
<html>
<head>
<!--Load the AJAX API-->
<script type="text/javascript">
// Load the Visualization API and the piechart package.
google.load('visualization', '1', {'packages':['columnchart']});
// Set a callback to run when the Google Visualization API is loaded.
google.setOnLoadCallback(drawChart);
function drawChart() {
// Create our data table out of JSON data loaded from server.
var data = new google.visualization.DataTable(<?=$jsonTable?>);
// Instantiate and draw our chart, passing in some options.
//do not forget to check ur div ID
var chart = new google.visualization.ColumnChart(document.getElementById('chart_div'));
chart.draw(data, {width: 400, height: 240});
}
</script>
</head>
<body>
<!--Div that will hold the pie chart-->
<div id="chart_div"></div>
</body>
</html>