gpt4 book ai didi

php - MySQLi fetch_all 的奇怪错误

转载 作者:行者123 更新时间:2023-11-29 02:52:19 24 4
gpt4 key购买 nike

这可能会被标记为重复,但我的错误似乎与我在 stackoverflow 上看到的其他错误不同。

下面的代码应该显示图像中的内容:代码:

 if($news_result = $db->query("SELECT * FROM `news` ORDER BY `likes` DESC LIMIT 4")) {                      
if ($news_result->num_rows) {
$rows = $news_result->fetch_all(MYSQL_ASSOC);
$row_count = 0;
foreach($rows as $row) {
$row_count++;

$content_echo = '
<div class="row inside" style="width: 99%; margin-left: auto; margin-right: auto;">
<a href="http://portuguesegaming.com/post/'.$row['url'].'">
<div class="view third-effect"
style="
background: url(../images/'.$background.'.png);
background-size:80%;
background-position: center;
margin-right: auto;
margin-left: auto;">
<h3>'.$row['title'].'</h3><br>
<table style="width: 78%;">
<tr>
<td>
<h4 style="font-size: 12px;">'.$row['description'].'</h4>
</td>
</tr>
<tr>
<td colspan="2">
<h4>BY: '.$row['creator'].'</h5>
</td>
</tr>
</table>
<div class="likes" style="margin-top: -20px;"><div class="likes-icon"></div><h4>'.$row['likes'].'</h4></div>
<div class="mask">
<h6>READ MORE</h6>
</div>
</div>
</a>
</div>';

$separator = ' <br>
<div class="separator" style="
margin-bottom: -25px;
margin-top: -25px;
background-image: linear-gradient(to right, rgba(254, 254, 254, 0), rgba(254, 254, 254, 0.75), rgba(254, 254, 254, 0));"></div>
<br>';

if ($news_result->num_rows > 1 && $row_count > 0 && $row_count < $news_result->num_rows) {
$content_echo .= $separator;
}
echo $content_echo;
}
}
}

图片: enter image description here

这适用于我的 wamp 服务器,但是当我将文件上传到 godaddy 的主机时,出现错误:Fatal error: Call to undefined method mysqli_result::fetch_all() in /home/ipsyko/public_html/index.php on line 102我读到了它,他们说这是因为 PHP 版本,goddady 的 PHP 版本是 5.4(native) 并且出现错误,我更改为正常 4.4(not native) 并且没有出现错误,但也没有出现我想要的内容,这很奇怪,然后我更改为 5.5 并发生了与 5.4 中发生的相同的事情不是原生的,我什至检查了“mysqlnd”选项,但没有任何效果。任何人都知道如何解决它?

最佳答案

我认为这段代码可以工作:

<?php
$news_result = $db->query("SELECT * FROM `news` ORDER BY `likes` DESC LIMIT 4");
if(mysqli_num_rows($news_result) >= 1){
while($row = mysqli_fetch_array($news_result)){

switch($row['type']){
case "global":$background = "globalnews";
break;
case "console":$background = "console_bg";
break;
case "pc":$background = "pc_bg";
break;
case "bar":$background = "bar_bg";
break;
default:$background = "";
}

$content_echo = '<div class="row inside" style="width: 99%; margin-left: auto; margin-right: auto;">
<a href="http://portuguesegaming.com/post/'.$row['url'].'">
<div class="view third-effect" style="background: url(../images/'.$background.'.png); background-size:80%; background-position: center; margin-right: auto; margin-left: auto;">
<h3>'.$row['title'].'</h3>
<table style="width: 78%;">
<tr>
<td><h4 style="font-size: 12px;">'.$row['description'].'</h4></td>
</tr>
<tr>
<td colspan="2"><h4>BY: '.$row['creator'].'</h4></td>
</tr>
</table>
<div class="likes" style="margin-top: -20px;"><div class="likes-icon"></div><h4>'.$row['likes'].'</h4></div>
<div class="mask">
<h6>READ MORE</h6>
</div>
</div>
</a>
</div>';

$separator = '<div class="separator" style="margin-bottom: -25px; margin-top: -25px; background-image: linear-gradient(to right, rgba(254, 254, 254, 0), rgba(254, 254, 254, 0.75), rgba(254, 254, 254, 0));"></div>';
echo $content_echo.$separator;
}
}
?>

关于php - MySQLi fetch_all 的奇怪错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34377990/

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