0
나는 다음의 Google Charts
코드를 가지고 있으며, MySQL
과 연결하려고합니다. 인터넷에서 사용할 수있는 모든 것을 시도했지만, 여전히 10 개의 항목이 있지만 SQL 결과 집합 중 하나만 표시합니다. . 인터넷에서 나는 $row_num
카운터 물건을 발견하고 그것을 내 코드에 포함시키기 때문에 한 항목을 쿼리 할 수 있었지만 모든 항목을 쿼리하려고합니다. 내 PHP 코드에 따라, 이것 좀 도와 제가 만들어왔다 어떤 실수 (있는 경우)를 알려 주시기 바랍니다 :Google Charts는 MySQL을 연결할 때 단 하나의 항목 만 표시합니까?
[<?php
``$dbhandle= new mysqli('localhost','root','8317','record');
//echo $dbhandle->connect_error();
$query= "SELECT * from download_manager";
$res= $dbhandle->query($query);
?>
<html>
<head>
<script type="text/javascript" src="https://www.gstatic.com/charts/loader.js"></script>
<script type="text/javascript">
google.charts.load('current', {'packages':\['bar'\]});
google.charts.setOnLoadCallback(drawStuff);
function drawStuff() {
var data = new google.visualization.arrayToDataTable(\[
\['Title', 'No. of Downloads'\],
<?php
$total_rows = mysqli_num_rows($res);
$row_num = 0;
if (mysqli_num_rows($res) > 0) {
while($row=$res->fetch_assoc())
{
$row_num++;
if ($row_num == $total_rows){
echo "\['".$row\['filename'\]."',".$row\['downloads'\]."\]";
}
}
}
else
{
echo "0 results";
}
?>
\]);
var options = {
width: 800,
chart: {
'title': 'Top 10 Downloads',
subtitle: 'for the last month'
},
bars: 'horizontal', // Required for Material Bar Charts.
axes: {
}
};
var chart = new google.charts.Bar(document.getElementById('dual_x_div'));
chart.draw(data, options);
};
</script>
</head>
<body>
See Also : <a href="barchart1.html"> Downloads in the Last 7 Years </a> <br> <br>
<div id="dual_x_div" style="width: 900px; height: 500px;"></div>
</body>
</html>][1]
트릭을 주셔서 감사합니다. :) –