I am getting error message: Invalid argument for foreach() in my View. I wanted to display all entries in my mysql table but i kept on getting error message. I am a newbie in Codeigniter and couldn't really figure out how to solve this. The codes are the following: My model (display_branch.php)
<?php if(!defined ('BASEPATH')) exit ('No direct script access allowed');
class Display_Branch extends CI_Model
{
function __construct()
{
parent::__construct();
}
public function getAll()
{
$this->db->select('bcode, bname, btel, badd');
$this->db->from('branches');
$query = $this->db->get();
if($query->num_rows() == 1)
{
$results = $query->result();
return $results;
}
else
{
return FALSE;
}
}
}?>
My Controller (link_controller.php) *only the snippet.
public function insert()
{
$this->load->model('display_branch');
$data['results'] = $this->display_branch->getAll();
$this->load->view('insert_branch');
$this->load->view('navigation');
$this->load->view('content_bc', $data);
$this->load->view('footers');
}
And my view(content_bc.php)
<?php
foreach($results as $row)
{
echo '<tr>';
echo '<td>'.$row->bcode.'</td>';
echo '<td>'.$row->bname.'</td>';
echo '<td>'.$row->btel.'</td>';
echo '<td>'.$row->badd.'</td>';
echo '</tr>';
}
?>
Please help me what to do. Thank you.