[英]What does Cannot use object of type mysqli_result as array mean?
I am trying to find the last teacher id from my database and getting this error. 我试图从我的数据库中找到最后一个老师ID,并得到此错误。 Fatal error: Cannot use object of type mysqli_result as array in .My Codes are as follows.
致命错误:无法将mysqli_result类型的对象用作 .My中的数组。我的代码如下。 Any Help ?
有帮助吗?
class tinyteacher {
public function getLastTeacherId(){
$query = ("SELECT `teacherid` FROM `teacher` ORDER BY `teacherid` DESC ");
$result = $this->db->select($query);
return $result;
}
}
<div class="col-sm-6">
<input type="text" name="teacherid" value="
<?php
$teacher = new tinyteacher();
$lastteacher = $teacher->getLastTeacherId();
echo $lastteacher;
?>
</div>
your function return $result; array object
您的
function return $result; array object
function return $result; array object
and you print array object
in echo
echo use for print string not for array
并且您在
echo
print array object
echo
echo use for print string not for array
so use print_r
instead of echo
所以使用
print_r
而不是echo
like print_r($lastteacher);
像
print_r($lastteacher);
Can't use object of type mysqli_result
as array
不能将
mysqli_result
类型的mysqli_result
用作array
Use
mysqli_fetch_assoc
ormysqli_fetch_array
to fetch a result row as an associative array.使用
mysqli_fetch_assoc
或mysqli_fetch_array
来获取结果行作为关联数组。
$query = "SELECT 1";
$result = $mysqli->query($query);
$data_array = $result->fetch_assoc()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.