我有一个小脚本查询我的数据库&建立一个谷歌图表。
效果很好,我看不出任何问题。但是,错误日志显示不同的故事。我得到以下内容:
错误记录 mysqli_fetch_array()期望参数1为mysqli_result,在第186行的/var/www/html/header.php中给出null
包含错误的代码行:
这是脚本。这是第186行: " while($ row = mysqli_fetch_array($ exec)){" - 大约是下面的一半。
完整脚本
<script type="text/javascript" src="https://www.google.com/jsapi"></script>
<script type="text/javascript">
google.load("visualization", "1", {packages:["corechart"]});
google.setOnLoadCallback(drawChart);
function drawChart() {
var data = google.visualization.arrayToDataTable([
['Date', 'Total Orders'],
<?php
$memberid = getLoggedMemberID();
$query = "SELECT date as complain_Date1, IFNULL(sum(count),0) as count
FROM (
SELECT Date_Closed as complain_Date1, count(id) as count
FROM Complaints
INNER JOIN membership_userrecords ON Complaints.id =
membership_userrecords.pkValue
where membership_userrecords.memberID = '$memberid' AND
membership_userrecords.tableName='Complaints' AND Date_Closed IS NOT
NULL
GROUP BY Date_Closed
) AS t
RIGHT JOIN dates ON t.complain_Date1 = dates.date
Where date between DATE_SUB(NOW(), INTERVAL 30 DAY) and CURRENT_DATE()
GROUP BY date
ORDER BY date asc";
$exec = mysqli_query($conn,$query);
while($row = mysqli_fetch_array($exec)){
echo "['".$row['complain_Date1']."',".$row['count']."],";
}
?>
]);
var options = {
'chartArea': {'width': '85%', 'height': '70%'},
legend: {position: 'none'},
colors: ['#2ab77e'],
is3D: true,
backgroundColor: { fill:'transparent' }
};
var chart = new google.visualization.AreaChart(document.getElementById("complaints"));
chart.draw(data, options);
}
</script>
有人能解决我的问题吗?
我在这里试过这个解决方案: error mysqli_fetch_array() expects parameter 1 to be mysqli_result, string given
但它只会使我的整个页面变白,所以必须有错误
答案 0 :(得分:0)
替换
while($row = mysqli_fetch_array($exec)){
与
while($row = mysqli_fetch_array($exec, MYSQLI_ASSOC)){
参考 https://www.tutorialspoint.com/php/mysql_select_php.htm了解详情
如果您需要进一步的帮助,请告诉我