gpt4 book ai didi

php - 错误日志中的错误PHP警告: Invalid argument supplied for foreach()

转载 作者:行者123 更新时间:2023-12-03 08:24:40 25 4
gpt4 key购买 nike

错误日志中有错误,但结果显示得很完美,我不知道如何以及为什么在错误文件中显示此错误。

PHP警告:为foreach()提供了无效的参数,请为此提供帮助。如何摆脱此错误?

<?php

$business_name = $value['business_name'];
$sql = "SELECT * FROM listings_reviews WHERE business_name = '$business_name' order by listing_date DESC";
$result = $conn -> query($sql);

while ($row = $result->fetch_assoc()) {
$data[] = $row;
}

//print_r($row); //exit;
?>


<?php
foreach ($data as $value){ ?>

<div class="col-md-12 reviews">
<span style="color:#000"><?php echo hide_mail ($value['reviewer_email'])?></span>&nbsp;&nbsp;
<span style="color:#000">
<?php

$starNumber = $value['rating'];

//echo $starNumber; exit;

for($x=1;$x<=$starNumber;$x++) {
echo '<i style="font-size:12px; color:#00BF9A" class="fa fa-star" aria-hidden="true"></i>';
}
if (strpos($starNumber,'.')) {
echo '<i style="font-size:12px; color:#00BF9A" class="fa fa-star-half-o" aria-hidden="true"></i>';
$x++;
}
while ($x<=5) {
echo '<i style="font-size:12px; color:#00BF9A" class="fa fa-star-o" aria-hidden="true"></i>';
$x++;
}
?>
</span>

<span style="float:right; color:#666; font-size:14px"><?php echo $value['listing_date']?></span>
<hr style="margin:5px">
<span style="color:#666"><?php echo $value['comment']?></span>





</div>
<?php
}

?>

最佳答案

在某些情况下,没有结果,因此永远不会调用$data[] = $row;且未定义$data

解决方法是正确初始化$data:

$data = []; // add this

while ($row = $result->fetch_assoc()) {
$data[] = $row;
}

关于php - 错误日志中的错误PHP警告: Invalid argument supplied for foreach(),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45256310/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com