我试图从数据库数据创建图表但是当我调用数据时它不会显示。我想问一下我的代码有什么问题吗? sql语句是错误的,因为我已经尝试检查代码,看起来一切看起来都很棒。 现在我有三个表,即评论,用户和upload_medicine。审查表是链接用户和upload_medicine主键,分别是user_id和medicine_id。 在图表中,我打算从评论表中调用用户总数,并从upload_medicine调用疾病名称。
//connect to database
$db=mysqli_connect("localhost","root","","authen");
$sql4="select * from review left join upload_medicine on review.medicineid=upload_medicine.medicine_id left join users on review.userid = users.user_id ";
$result4=mysqli_query($db,$sql4);
?>
<!DOCTYPE html>
<html>
<head>
<title> TCHM </title>
<link rel="stylesheet" type="text/css" href="style01.css"/>
<script type="text/javascript" src="https://www.gstatic.com/charts/loader.js"></script>
<script type="text/javascript">
google.charts.load('current', {'packages':['corechart']});
google.charts.setOnLoadCallback(drawChart);
function drawChart() {
var data = google.visualization.arrayToDataTable([
['Bil', 'Illness'],
<?php
while($row=mysqli_fetch_assoc(result4)){
echo"['".$row['sum(userid)']."',".$row['illness_name']."],";
}
?>
]);
var options = {
title: 'The total user faced the illness'
};
var chart = new google.visualization.PieChart(document.getElementById('piechart'));
chart.draw(data, options);
}
</script>