【发布时间】:2015-01-16 09:09:50
【问题描述】:
昨天我var_dump($this->m_test->result_getGrades());它给了我一个数组[1356],现在它返回了null。谁能帮我弄清楚为什么它是NULL?我还是 PHP 和 Codeigniter 的新手,弄清楚为什么我不能从我的数据库中检索任何数据是非常有压力的。
我假设出现此错误的原因是因为 ($this->m_test->result_getGrades()) 为 NULL
遇到了 PHP 错误
严重性:警告
消息:为 foreach() 提供的参数无效
文件名:views/v_display.php
行号:7
另外,我无法从数据库中检索任何数据的原因是什么?供日后参考
这是我的代码:
控制器 c_test.php
function getGrades() {
$data['query'] = $this->m_test->result_getGrades();
$this->load->view('v_display', $data);
}
模型 m_test.php
function result_getGrades()
{
$this->db->select('grades.blockcode,subjectblocking.subjectcode,subjects.description,grades.final');
$this->db->from('grades');
$this->db->join('subjectblocking','grades.blockcode=subjectblocking.blockcode');
$this->db->join('subjects','subjectblocking.subjectcode=subject.subjectcode');
$this->db->where('2013-F019');
$query=$this->db->get();
}
查看 v_display.php
<?php foreach ($query as $row): ?>
<?php echo $row->studentid;?><br>
<?php echo $row->subjectcode;?><br>
<?php echo $row->description;?><br>
<?php echo $row->final;?><br>
<?php endforeach; ?>
再次感谢您! :)
【问题讨论】:
-
我不知道 CodeIgniter,但也许你得到 NULL 是因为查询本身,可能是 where 条件或连接导致了这个问题。
标签: php codeigniter null var-dump