这个 "Message: Undefined property: stdClass" 是什么意思?

What does this "Message: Undefined property: stdClass" mean?

我是 codeigniter 和 php 的新手,我现在遇到这个错误,我不知道我哪里出错了。我应该在我的 foreach 上添加一些东西吗?上次我遇到的是一个未定义的 属性 是因为我的模型中的一个拼写错误的单词现在是一个 stdClass?这次没有单词拼错。有人可以就这个问题启发我吗?

错误:

A PHP Error was encountered

Severity: Notice

Message: Undefined property: stdClass::$blockcode

Filename: views/v_schedule.php

Line Number: 10

观点:v_schedule.php

<?php foreach ($query as $row){ ?>


                       <?php echo $row->blockcode;?> <br>
                       <?php echo $row->subjectcode;?> <br>
                       <?php echo $row->daystart;?> <br>
                       <?php echo $row->dayend;?>   <br>
                       <?php echo $row->stime;?>    <br>
                       <?php echo $row->sday;?> <br>
                       <?php echo $row->instructorname;?>   <br>
                       <?php echo $row->instuctorlastname;?>    <br>
                       <?php echo $row->roomcode;?> <br>
                       <?php echo $row->building;?> <br>

        <?php } ?>  

控制器:c_test.php

 function getSchedule() {
       $data['query'] = $this->m_test->result_getSchedule();
       $this->load->view('v_schedule',$data);
 }

型号:m_test.php

function result_getSchedule()

    {
        $this->db->select('grades.studentid', 'grades.blockcode', 'subjectblocking.subjectcode','subjectblocking.daystart','subjectblocking.dayend', 'subjectblocking.stime','subjectblocking.sday','instructorinfo.firstname', 'instructorinfo.lastname', 'subjectblocking.roomcode','room.building');
        $this->db->from('grades');
        $this->db->join('subjectblocking', 'grades.blockcode=subjectblocking.blockcode');
        $this->db->join('instructorinfo', 'subjectblocking.instructorid=instructorinfo.instructorid');
        $this->db->join('room', 'subjectblocking.roomcode= room.roomcode');
        $this->db->distinct();
        $this->db->where('studentid', '2013-F0218');
        $query=$this->db->get();
        return $query->result();
    }

成绩和主题屏蔽表中有两个块代码列。

您应该像这样更改 m_test.php 中的 sql :

 $this->db->select('grades.studentid', 'grades.blockcode as block_code', 'subjectblocking.subjectcode','subjectblocking.daystart','subjectblocking.dayend', 'subjectblocking.stime','subjectblocking.sday','instructorinfo.firstname', 'instructorinfo.lastname', 'subjectblocking.roomcode','room.building');

并且您应该在 v_schedule.php

中将 $row->blockcode 变量更改为 $row->block_code

希望对您有所帮助。

你犯了一个错误

$this->db->select('grades.studentid', 'grades.blockcode', 'subjectblocking.subjectcode','subjectblocking.daystart','subjectblocking.dayend', 'subjectblocking.stime','subjectblocking.sday','instructorinfo.firstname', 'instructorinfo.lastname', 'subjectblocking.roomcode','room.building');
//this is is not right way codeigniter select.
//it only selects studentid
//blockcode is not seleted that's why you got that error

这是正确的方法

 $this->db->select('grades.studentid , grades.blockcode , subjectblocking.subjectcode , subjectblocking.daystart , subjectblocking.dayend , subjectblocking.stime , subjectblocking.sday , instructorinfo.firstname , instructorinfo.lastname ,  subjectblocking.roomcode , room.building');

希望这能解决您的问题

首先我也使用了上面的代码,我得到了同样的错误。

$this->db->select('grades.studentid', 'grades.blockcode as block_code', 'subjectblocking.subjectcode','subjectblocking.daystart','subjectblocking.dayend', 'subjectblocking.stime','subjectblocking.sday','instructorinfo.firstname', 'instructorinfo.lastname', 'subjectblocking.roomcode','room.building');

但是通过改变

$this->db->select('grades.studentid, grades.blockcode as block_code, subjectblocking.subjectcode,subjectblocking.daystart,subjectblocking.dayend, subjectblocking.stime,subjectblocking.sday,instructorinfo.firstname, instructorinfo.lastname, subjectblocking.roomcode,room.building');

我解决了错误。

如果我们可以给 grades.studentid 一个单独的名称作为 studentID 就更好了,那么我们可以直接调用:

echo $query->studentID;