The problem is my database does not have a password and still its not
working. Kindly check to see if there is anything i did not do right
<?php
$username = 'localhost';
$password = '';
$databasename = 'mobiledb';
try {
$db = new PDO("mysql:dbname = $mobiledb", $localhost, $);
}
catch (PDOException $e) {
die("{error: {$e->getMessage()}}");
}
$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$query = $db->prepare("SELECT Q1, Q2, FROM table2");
try {
$query->execute();
$results = $query->fetchAll(PDO::FETCH_ASSOC);
}
catch (PDOException $e) {
die("{error: {$e->getMessage()}}");
}
$table = array(
'cols' => array(
array('label' => 'Q1' , 'type' => '<varchar>'),
array('label' => 'Q2' , 'type' => '<varchar>')
// etc
),
'rows' => array()
);
foreach ($results as $r) {
$table['rows'][] = array('c' => array(
array('v' => $r['Q1']),
array('v' => $r['Q2'])
// etc
));
}
?>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<title>My Chart</title>
<script type='text/javascript' src="http://www.google.com/jsapi"></script>
<script type='text/javascript'>
//<![CDATA[
function drawChart () {
var data = new google.visualization.DataTable(<?php echo
json_encode($table, JSON_NUMERIC_CHECK); ?>);
var chart = new
google.visualization.LineChart(document.querySelector('#chart_div'));
chart.draw(data, {
height: 400,
width: 600
});
}
google.load('visualization', '1', {packages:['corechart'], callback:
drawChart});
//]]>
</script>
</head>
<body>
<div id="chart_div"></div>
</body>
</html>
--
You received this message because you are subscribed to the Google Groups
"Google Visualization API" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/google-visualization-api.
For more options, visit https://groups.google.com/groups/opt_out.