警告:mysqli :: query():无法在C:\ xampp \ htdocs \ palo \ graph.php中获取mysqli
我有不同的选项卡应显示不同的图表。第一个选项卡显示没有问题的第一个图表,但我在第二个选项卡中显示第二个图表时遇到问题。当我点击第二个选项卡上,我只是不断收到这些错误:警告: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}");
我不知道错误是什么意思,因为我还是这个新手。我希望有人可以看看这个问题,并帮助我修复我的代码。非常感谢!
回答:
那么,你在第一个图表之后关闭$dbhandle
,所以它和mysqli连接不可用于第二个查询。
将其保持打开状态,直至完成所有查询。因此,仅在最后一次查询后使用$dbhandle->close();
。
以上是 警告:mysqli :: query():无法在C:\ xampp \ htdocs \ palo \ graph.php中获取mysqli 的全部内容, 来源链接: utcz.com/qa/261589.html