我有不同的選項卡應顯示不同的圖表。第一個選項卡顯示沒有問題的第一個圖表,但我在第二個選項卡中顯示第二個圖表時遇到問題。當我點擊第二個選項卡上,我只是不斷收到這些錯誤:警告:mysqli :: query():無法在C: xampp htdocs palo graph.php中獲取mysqli
Warning: mysqli::query(): Couldn't fetch mysqli in C:\xampp\htdocs\palo\graph.php on line 248
Warning: main(): Couldn't fetch mysqli in C:\xampp\htdocs\palo\graph.php on line 248
Warning: main(): Couldn't fetch mysqli in C:\xampp\htdocs\palo\graph.php on line 248
Error code():
這裏是我的代碼:
<div id="c2017" class="tabcontent">
<center>
<?php
$strQuery = "SELECT COUNT(*) as student_count, exam_year, result FROM studentsinfo WHERE exam_year = 2017 GROUP BY result ORDER BY student_count DESC";
$result = $dbhandle->query($strQuery) or exit("Error code ({$dbhandle->errno}): {$dbhandle->error}");
if ($result) {
$arrData = array(
"chart" => array(
"caption" => "TEST RESULTS GRAPH FOR SCHOOL YEAR 2017",
"showValues" => "0",
"theme" => "fint"
)
);
$arrData["data"] = array();
while($row = mysqli_fetch_array($result)) {
array_push($arrData["data"], array(
"label" => $row["result"],
"value" => $row["student_count"]
)
);
}
$jsonEncodedData = json_encode($arrData);
$columnChart = new FusionCharts("column2D", "myFirstChart" , 700, 400, "chart-1", "json", $jsonEncodedData);
$columnChart->render();
$dbhandle->close();
}
?>
<br>
<div id="chart-1"></div>
</center>
</div>
<div id="c2018" class="tabcontent">
<center>
<?php
$strQuery2 = "SELECT COUNT(*) as student_count, exam_year, result FROM studentsinfo WHERE exam_year = 2018 GROUP BY result ORDER BY student_count DESC";
$result2 = $dbhandle->query($strQuery2) or exit("Error code ({$dbhandle->errno}): {$dbhandle->error}");
if ($result2) {
$arrData2 = array(
"chart" => array(
"caption" => "TEST RESULTS GRAPH FOR SCHOOL YEAR 2018",
"showValues" => "0",
"theme" => "fint"
)
);
$arrData2["data"] = array();
while($row2 = mysqli_fetch_array($result2)) {
array_push($arrData2["data"], array(
"label" => $row2["result"],
"value" => $row2["student_count"]
)
);
}
$jsonEncodedData2 = json_encode($arrData2);
$columnChart2 = new FusionCharts("column2D", "mySecondChart" , 700, 400, "chart-2", "json", $jsonEncodedData2);
$columnChart2->render();
$dbhandle->close();
}
?>
<br>
<div id="chart-2"></div>
</center>
</div>
的錯誤是什麼地方在:
$strQuery2 = "SELECT COUNT(*) as student_count, exam_year, result FROM studentsinfo WHERE exam_year = 2018 GROUP BY result ORDER BY student_count DESC";
$result2 = $dbhandle->query($strQuery2) or exit("Error code ({$dbhandle->errno}): {$dbhandle->error}");
我不知道錯誤是什麼意思,因爲我還是這個新手。我希望有人可以看看這個問題,並幫助我修復我的代碼。非常感謝!
哦,現在我知道了。非常感謝!! – Dza