I am working on a small application that displays data from a database table. I am getting 2 errors and dont know why are there, and I cant figure it out as I am still a noob. I guess its something stupid, please help.
ERRORS
A PHP Error was encountered
Severity: Notice
Message: Undefined variable: querys
Severity: Warning
Message: Invalid argument supplied for foreach()
these errors are located in my view page.
VIEW
<?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; ?>
CONTROLLER
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);
}
MODEL
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;
}
EDIT
i fixed the foreach error by inserting
<?php if(is_array($queries)): ?>
<?php endif; ?>
the only error i am getting is the
A PHP Error was encountered
Severity: Notice
Message: Undefined variable: queries