So what I've already got is 2 php files. the first one lets you choose the student name from a dropdown list and the second one populates the chart.
first script
<html>
<head>
<!--Load the AJAX API-->
<script type="text/javascript" src="http://www.google.com/jsapi"></script>
<script type="text/javascript" src="jquery-1.7.1.min.js"></script>
<script type="text/javascript">
// Load the Visualization API and the piechart,table package.
google.load('visualization', '1', {'packages':['corechart','table']});
function drawItems(num) {
var jsonPieChartData = $.ajax({
url: "getpiechartdata.php",
data: "q="+num,
dataType:"json",
async: false
}).responseText;
var jsonTableData = $.ajax({
url: "gettabledata.php",
data: "q="+num,
dataType:"json",
async: false
}).responseText;
// Create our data table out of JSON data loaded from server.
var piechartdata = new google.visualization.DataTable(jsonPieChartData);
var tabledata = new google.visualization.DataTable(jsonTableData);
// Instantiate and draw our pie chart, passing in some options.
var chart = new google.visualization.PieChart(document.getElementById('chart_div'));
chart.draw(piechartdata, {
width: 700,
height: 500,
chartArea: { left:"5%",top:"5%",width:"90%",height:"90%" }
});
// Instantiate and draw our table, passing in some options. var table = new google.visualization.Table(document.getElementById('table_div'));
table.draw(tabledata, {showRowNumber: true, alternatingRowStyle: true});
}
</script>
</head>
<body>
<form>
<select name="users" onchange="drawItems(this.value)">
<option value="">Select a student:</option>
<?php
$dbuser="";
$dbname="";
$dbpass="";
$dbserver="";
// Make a MySQL Connection
mysql_connect($dbserver, $dbuser, $dbpass) or die(mysql_error());
mysql_select_db($dbname) or die(mysql_error());
// Create a Query
$sql_query = "SELECT user_id, user_name FROM students";
// Execute query
$result = mysql_query($sql_query) or die(mysql_error());
while ($row = mysql_fetch_array($result)){
echo '<option value='. $row['user_id'] . '>'. $row['user_name'] . '</option>';
}
mysql_close($con);
?>
</select>
</form>
<div id="chart_div"></div>
<div id="table_div"></div>
</body>
</html>
and this php file to populate the chart based on the student id selected
<?php $q=$_GET["q"]; $dbuser=""; $dbname=""; $dbpass=""; $dbserver=""; $sql_query = "SELECT task_status, COUNT(*) FROM tasks WHERE task_student_id=" . $q . "" $con = mysql_connect($dbserver,$dbuser,$dbpass); if (!$con){ die('Could not connect: ' . mysql_error()); } mysql_select_db($dbname, $con); $result = mysql_query($sql_query); $data = array('cols' => array(array('label' => 'Not completed', 'type' => 'string'), array('label' => 'Completed', 'type' => 'string')), 'rows' => array()); while($row = mysql_fetch_row($result)) { $data['rows'][] = array('c' => array(array('v' => $row[0]), array('v' => $row[1]))); } echo json_encode($data); mysql_close($con); ?>
There definitely is something wrong with the second php file, could anyone please help as its for a school project?
Thanks in adnvance