Php 致命错误:未捕获错误:无法将mysqli_result类型的对象用作数组。如何打印表的属性?
我试图打印查询结果,但出现以下错误: 致命错误:未捕获错误:无法将mysqli_result类型的对象用作数组 我是PHP7的新手,总是用PHP5。为了打印结果,我尝试了不同的方法。但我还是犯了同样的错误Php 致命错误:未捕获错误:无法将mysqli_result类型的对象用作数组。如何打印表的属性?,php,html,mysql,Php,Html,Mysql,我试图打印查询结果,但出现以下错误: 致命错误:未捕获错误:无法将mysqli_result类型的对象用作数组 我是PHP7的新手,总是用PHP5。为了打印结果,我尝试了不同的方法。但我还是犯了同样的错误 $conn=mysqli_connect("localhost","root","","vivereingegneria") OR DIE(mysqli_error()); //QUERY $str= "SELECT `Titolo`,`Sottotitolo`,`Con
$conn=mysqli_connect("localhost","root","","vivereingegneria") OR
DIE(mysqli_error());
//QUERY
$str= "SELECT `Titolo`,`Sottotitolo`,`Contenuto` FROM `Articoli` WHERE
`Autore`= 'Name';";
//Execute the query
$result=mysqli_query($conn,$str);
($riga=mysqli_num_rows($result));
//Count rows and print
while($riga!=0){
echo' <!-- ABOUT -->
<section id="about" data-stellar-background-ratio="0.5">
<div class="container">
<div class="row">
<div class="col-md-6 col-sm-12">
<div class="about-info">
<div class="section-title wow fadeInUp" data-wow-delay="0.2s">
<h4>'.$result['Titolo'].'</h4>
<h2>'.$result['Sottotitolo'].'</h2>
</div>
<div class="wow fadeInUp" data-wow-delay="0.4s">
<p>'.$result['Contenuto'].'</p>
</div>
</div>
</div>
<!--Templatetemo style per cambiare immagini!!!-->
<div class="col-md-6 col-sm-12">
<div class="wow fadeInUp about-image" data-wow-delay="0.6s">
<img src="'.$result['Cover'].'" class="img-responsive" alt="">
</div>
</div>
</div>
</div>
</section>';
$riga--;
}
?>
$conn=mysqli\u connect(“localhost”、“root”、“vivereingegneria”)或
DIE(mysqli_error());
//质疑
$str=“从'Articoli'中选择'Titolo','sottoitolo','contentuto'
`Autore`=“Name”;”;
//执行查询
$result=mysqli_查询($conn,$str);
($riga=mysqli_num_rows($result));
//计算行数并打印
而($riga!=0){
回声'
“.$result['Titolo']”
“.$result['sottoitolo']”
“.$result['Contenuto']”
';
$riga--;
}
?>
尝试如下更改while循环:
while ($row = mysqli_fetch_assoc($result)) {
// Your code here
}
在while循环中,使用$row[]
而不是$result[]
,例如$row['Titolo']
您不需要任何riga计数器,只要获取所有结果,while循环就会终止我认为这是不同的,我不想要那个结果您需要获取结果-
$row=mysqli\u fetch\u assoc($result)
-请参阅