mysqli:无法将mysqli_result转换为字符串 [英] mysqli : mysqli_result could not be converted to string
本文介绍了mysqli:无法将mysqli_result转换为字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我知道已经问过许多类似这样的问题,但是我无法将其转化为我的问题,所以这就是为什么我再次提出问题.该代码过去可以正常工作,但是由于不建议使用mysql,因此我想将其转换为mysqli.
I know there have been asked lots of similair questions like this one, but I just can't translate it to my problem so thats why I ask again. The code used to work fine but since the mysql is going to be deprecated I wanted to translate to mysqli.
尝试从数据库中读取内容时收到以下错误:可捕获的致命错误:mysqli_result类的对象无法转换为字符串.它指的是第12行,即
I receive the following error when trying to read something from database: Catchable fatal error: Object of class mysqli_result could not be converted to string. It refers to line 12, which is
echo $result;
完整代码:
$previd ="10";
$query="SELECT * FROM contacts WHERE id='$previd'";
$result = $mysqli->query($query);
echo $result;
$num=$result->num_rows;
$mysqli->close();
echo "<b><center>Database Output</center></b><br><br>";
$i=0;
while ($i < $num) {
$id=mysql_result($result,$i,"id");
$first=mysql_result($result,$i,"first");
$last=mysql_result($result,$i,"last");
$phone=mysql_result($result,$i,"phone");
$mobile=mysql_result($result,$i,"mobile");
$fax=mysql_result($result,$i,"fax");
$email=mysql_result($result,$i,"email");
$web=mysql_result($result,$i,"web");
$content=mysql_result($result,$i,"content");
echo "<u>$id</u><b>$first $last</b><br>Phone: $phone<br>Mobile: $mobile<br>Fax: $fax<br>E-mail: $email<br>Web: $web<br><hr><br>$content";
$i++;
}
我该如何解决?
推荐答案
$num=$result->num_rows;
echo "<b><center>Database Output</center></b><br><br>";
while ($row = $result->fetch_assoc()) {
echo "<u>".$row['id']."</u><b>".$row['first']."</b>"; //etc...
}
容易得多.
这篇关于mysqli:无法将mysqli_result转换为字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文