I have tried doing research for about an hour on extract in PHP and assoc arrays but have not found the answer I need.
The problem is I am trying to create a pie chart using a google visualization API but am unable to pass data to the function because the extract function I am using in my PHP file is returning 0 meaning that no variables were successfully extracted.
Here is all of the relevant code for making the pie chart.
and here is a picture of the resulting output (ps the comment where it says load api is where the above php code ends):
$GradeDistQuery = "select avg(PCT_A),avg(PCT_B),avg(PCT_C),avg(PCT_DF) from GradeDistribution where Course = $CourseNumRow->Course and Subject='$SubjectRow->Subject' ";
$GradeDistResult = mysql_query($GradeDistQuery);
$GradeRow=mysql_fetch_assoc($GradeDistResult); // for the amount of rows the query returns echo the CourseTitle and Course(number)
//-display the result of the array
//TODO: Limit 1 result per class title ie CS as field of wrk stdy should only appear one time not 3
echo "<ul>\n";
echo "<p> Average percent of Students Who Got an A: </p>";
echo "<p class='rows'>".$GradeRow['avg(PCT_A)']."</p>";
echo "<p> Average percent of Students Who Got a B: </p>";
echo "<p class='rows'>".$GradeRow['avg(PCT_B)']."</p>";
echo "<p> Average percent of Students Who Got a C: </p>";
echo "<p class='rows'>".$GradeRow['avg(PCT_C)']."</p>";
echo "<p> Average percent of Students Who Got a D or a F: </p>";
echo "<p class='rows'>".$GradeRow['avg(PCT_DF)']."</p>";
echo "</ul>";
$GradeTable = extract($GradeRow);
echo "<p> extract return value = $GradeTable</p>";
<!-- en load api -->
<script type="text/javascript" src="http://www.google.com/jsapi"></script>
<script type="text/javascript">
//load package
google.load('visualization', '1', {packages: ['corechart']});
</script>
<script type="text/javascript">
function drawVisualization() {
// Create and populate the data table.
var data = google.visualization.arrayToDataTable([
['Grade', ' average percent of students who got that grade'],
<?php
while( $Graderow = mysql_fetch_assoc($GradeDistResult) ){
echo "<p> hello friend</p>";
extract($GradeRow);
//echo "['{$name}', {$ratings}],";
}
?>
]);
// Create and draw the visualization.
new google.visualization.PieChart(document.getElementById('visualization')).
draw(data, {title:"Average Grade Distribution for: "});
}
google.setOnLoadCallback(drawVisualization);
</script>
Here is a picture of the resulting output:
Any suggestions to as why extract is returning 0?