【发布时间】:2015-01-16 15:31:38
【问题描述】:
我是 codeigniter 和 php 的新手,我现在遇到这个错误,我不知道我哪里出错了。我应该在我的 foreach 上添加一些东西吗?上次我遇到的是一个未定义的属性,由于我的模型中的拼写错误现在是 stdClass?这次没有单词拼错。有人能告诉我这个问题吗?
错误:
遇到了 PHP 错误
严重性:通知
消息:未定义属性:stdClass::$blockcode
文件名:views/v_schedule.php
行号: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();
}
【问题讨论】:
-
听起来
$row不包含名为blockcode的属性。尝试在foreach循环中添加print_r($row); echo "<br /><br />";以查看每个$row值包含的内容。您可能错过了该属性... -
你也可以在这里php.net/manual/en/errorfunc.constants.php查看不同类型的php错误。
-
如果你用结果值加载你的
m_test然后传递一个模型实例在控制器中查看会更好。最好让它成为 MVC。 -
@War10ck 它告诉我 array(1) { [0]=> object(stdClass)#23 (1) { ["studentid"]=> string(10) "2013-F0218" } }
-
@AsimAwan 我以为我在做的是 mvc。模型是我放置所有查询的地方,我的 foreach 只是调用我想在我的数据库中检索的选定行
标签: php codeigniter