[eluser]clintonbeattie[/eluser]
Hi,
I'm having problems displaying my blog categories.
My category table is called "category" and I have two fields, one "id" and the other "cat_name".
Any help welcome...
MODEL
Code:
function getAllCategories(){
$data = array();
//all records from the database are retrieved as an array.
$this->db->select('cat_name');
$this->db->from('category');
$Q = $this->db->get();
if ($Q->num_rows() > 0) {
foreach ($Q-> result_array() as $row) {
$data[] = $row;
}
}
$Q-> free_result();
return $data;
}
CONTROLLER
Code:
function cat_nav()
{
$data['categories'] = $this->MBlog->getAllCategories();
$data['secondary_content'] = 'blog_secondary_content';
$this->load->vars($data);
$this->load->view('template');
}
VIEW
Code:
foreach ($categories as $key => $category) {
echo "<p>".$category['cat_name']."</p>";
}
ERRORS DISPLAYED
Code:
A PHP Error was encountered
Severity: Notice
Message: Undefined variable: categories
Filename: views/blog_secondary_content.php
Line Number: 8
A PHP Error was encountered
Severity: Warning
Message: Invalid argument supplied for foreach()
Filename: views/blog_secondary_content.php
Line Number: 8