在关联数组

时间:2016-11-15 18:11:58

标签: javascript php html mysql google-visualization

我已尝试在PHP和关联数组中进行大约一个小时的提取研究但未找到我需要的答案。

问题是我正在尝试使用谷歌可视化API创建一个饼图,但无法将数据传递给该函数,因为我在我的PHP文件中使用的提取函数返回0意味着没有成功提取变量。

以下是制作饼图的所有相关代码。

这里是结果输出的图片(ps注释,表示加载api是上面的php代码结束的地方):

$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>

以下是结果输出的图片:

enter image description here

为什么提取物返回0的任何建议?

0 个答案:

没有答案