我试着用codeigniter在我的模型上做一个foreach
,但是它给了我一个错误并返回结果。
代码如下:
public function read(){
$questions; //array
$query = $this->db->get('questions');
foreach($query->result() as $row){
$getAnswers = $this->db->get_where('answers', array('question_id'=>$row['question_id]']), 4);
$questions= $getAnswers;
}
return $questions;
}
这就是错误:
致命错误:无法将stdClass类型的对象用作
最佳答案
作为对象访问:
$getAnswers = $this->db->get_where('answers',
array('question_id'=>$row->question_id), 4);