我正在尝试根据MYSQL中的数据在PHP中生成JavaScript图表 不确定此代码有什么问题,因为所有标签都已正确放置。 以下是我的代码。 任何帮助将不胜感激。 感谢
<?php
include("includes/fusioncharts.php");
$hostdb = "localhost"; // MySQl host
$userdb = "root"; // MySQL username
$passdb = ""; // MySQL password
$namedb = "fusioncharts_phpsample"; // MySQL database name
$dbhandle = new mysqli($hostdb, $userdb, $passdb, $namedb);
if ($dbhandle->connect_error) {
exit("There was an error with your connection: ".$dbhandle->connect_error);
}
$strQuery = "SELECT Name, Population FROM Country ORDER BY Population DESC LIMIT 10";
$result = $dbhandle->query($strQuery) or exit("Error code ({$dbhandle->errno}): {$dbhandle->error}");
if ($result) {
$arrData = array(
"chart" => array
(
"caption" => "Top 10 Most Populous Countries",
"paletteColors" => "#0075c2",
"bgColor" => "#ffffff",
"borderAlpha"=> "20",
"canvasBorderAlpha"=> "0",
"usePlotGradientColor"=> "0",
"plotBorderAlpha"=> "10",
"showXAxisLine"=> "1",
"xAxisLineColor" => "#999999",
"showValues" => "0",
"divlineColor" => "#999999",
"divLineIsDashed" => "1",
"showAlternateHGridColor" => "0"
)
);
$arrData["data"] = array();
while($row = mysqli_fetch_array($result)) {
array_push($arrData["data"], array(
"label" => $row["Name"],
"value" => $row["Population"]
)
);
}
$jsonEncodedData = json_encode($arrData);
$columnChart = new FusionCharts("column2D", "myFirstChart" , 600, 300, "chart-1", "json", $jsonEncodedData);
$columnChart->render();
$dbhandle->close();
?>
答案 0 :(得分:1)
您错过了}
行的结束if ($result) {
。
答案 1 :(得分:1)
if ($result) {
条件不会在任何地方结束,因为}
缺失。
在最后一行添加}
。