codeigniter 代码点火器3:不允许在变量中插入的条件查询结果-不能将stdClass类型的对象用作数组[已关闭]

ftf50wuq  于 2023-01-10  发布在  其他
关注(0)|答案(1)|浏览(120)

这个问题是由打字错误或无法再重现的问题引起的。虽然类似的问题在这里可能是on-topic,但这个问题的解决方式不太可能帮助未来的读者。
昨天关门了。
Improve this question
类型:错误消息:不能将stdClass类型的对象用作数组$data ['retVal ']= $query-〉result();这是我得到一个错误的地方

$this->db->select('questions.*'); 
      $this->db->from('questions,test_question');
      $this->db->where('questions.id=test_question.question_id');
      $this->db->where('test_question.test_id = '.$test_id);
      $query = $this->db->get();
      $data['retVal']=$query->result();

这是我的观点,数据应该显示

<?php
                                    $i=0;
                                        foreach ($retVal as $data )
                                        {
                                            $i++;
                                            echo '<tr>
                                                        <td>'.$i.'</td>
                                                        <td>'.$data->question.'</td>
                                                            <td>'.$data->choice1.'</td>
                                                            <td>'.$data->choice2.'</td>
                                                            <td>'.$data->choice3.'</td>
                                                            <td>'.$data->choice4.'</td>
                                                            <td>'.$data->right_choice.'</td>
                                                            <td>'.$data->score.'</td>
                                                            <td>
                                                                <a href="'.base_url('Student/deleteStudent/'.$data->id).'">
                                                                <button type="button" class="btn btn-danger btn-sm">Delete</button>
                                                                </a>
                                                                <a href="'.base_url('Student/loadUpdateStudentView/'.$data->id).'">
                                                                <button type="button" class="btn btn-success btn-sm">Update</button>
                                                                </a>
                                                            </td>
                                                        </tr>';

                                    }

                                    ?>
weylhg0b

weylhg0b1#

我在key中使用了$data变量,当我重命名发送到视图的变量时,它会产生问题,它解决了问题

foreach ($randomQuestions as $data ){
            // insert all the record in test_question table
            $recdata = array(
             'test_id'=>$test_id,
             'question_id'=>$data->id
            );

相关问题