我正在开发一个显示数据库表中数据的小型应用程序。我收到 2 个错误,不知道为什么会出现,而且我还是个菜鸟,所以我无法弄清楚。我想这是愚蠢的,请帮助。
错误
A PHP Error was encountered
Severity: Notice
Message: Undefined variable: querys
Severity: Warning
Message: Invalid argument supplied for foreach()
这些错误位于我的视图页面中。
看法
<?php foreach ($queries as $row): ?>
<table>
<th>Name</th>
<th>Surname</th>
<th>phone</th>
<th>email</th>
<td><?php echo $row->name; ?></td>
<td><?php echo $row->surname; ?></td>
<td><?php echo $row->phone; ?></td>
<td><?php echo $row->email; ?></td>
</table>
<?php endforeach; ?>
控制器
function display($offset = 0)
{
$limit = 20;
$this->load->model('info_model');
$results = $this->info_model->search($limit, $offset);
$data['queries'] = $results['rows'];
$data['num_results'] = $results['num_rows'];
$this->load->view('info_view',$data);
}
模型
function search ($limit, $offset){
//results query
$q = $this->db->select('ID, name, surname, phone, email');
$this->db->from('tblinfo');
$this->db->limit($limit, $offset);
$ret['rows'] = $q->get()->result();
//count query
$q = $this->db->select('COUNT(*) as count', FALSE )
->from('tblinfo');
$tmp = $q->get()->result();
$ret['num_rows'] = $tmp[0]->count;
return $ret;
}
编辑
我通过插入修复了 foreach 错误
<?php if(is_array($queries)): ?>
<?php endif; ?>
我得到的唯一错误是
A PHP Error was encountered
Severity: Notice
Message: Undefined variable: queries