简体   繁体   English

不能将mysqli_result类型的对象用作数组是什么意思?

[英]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 or mysqli_fetch_array to fetch a result row as an associative array. 使用mysqli_fetch_assocmysqli_fetch_array来获取结果行作为关联数组。

$query = "SELECT 1";
$result = $mysqli->query($query);
$data_array = $result->fetch_assoc()

and for more reference click here 有关更多参考,请单击此处

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 mysqli错误:无法将mysqli_result类型的对象用作数组 - mysqli error : Cannot use object of type mysqli_result as array 致命错误:无法将mysqli_result类型的对象用作数组 - Fatal error: Cannot use object of type mysqli_result as array 无法将mysqli_result类型的对象用作数组错误 - Cannot use object of type mysqli_result as array error 不能在php Mysql中使用mysqli_result类型的对象作为数组 - Cannot use object of type mysqli_result as array in php Mysql Mysqli依靠php“不能将mysqli_result类型的对象用作数组” - Mysqli count on php “Cannot use object of type mysqli_result as array” 使用mysqli-&gt; fetch_assoc()-无法将mysqli_result类型的对象用作数组 - Using mysqli->fetch_assoc() - Cannot use object of type mysqli_result as array mysqli_result对象中的&#39;type&#39;属性代表什么? - What does the 'type' property in the mysqli_result object represent? 致命错误:无法在第97行上将mysqli_result类型的对象用作数组。 - Fatal error: Cannot use object of type mysqli_result as array in…on line 97 致命错误:不能将mysqli_result类型的对象用作C:\\ xampp \\中的数组 - Fatal error: Cannot use object of type mysqli_result as array in C:\xampp\ sql + php-致命错误:无法将mysqli_result类型的对象用作数组,为什么 - sql + php - Fatal error: Cannot use object of type mysqli_result as array why
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM