[eluser]Andy UK[/eluser]
Your code was a great help, Thank you!
I've almost got it working, but I'm stuck on getting the info out of the category result. I still haven't been able to get my head around the whole object, multi-dimensional array thing. I'm getting the error message "Message: Trying to get property of non-object" in the view, but on a positive note, the error appears the correct number of times, ie. Twice if a post has two categories, three times if there are three categories, etc.
Below is a test example to show you what I'm getting back from the database with an arbitrary post number 3:
Code:
$test_category = $this->blog_model->getPostCategories(3);
And a print_r in the view of the variable $test_category gives:
Code:
Array ( [0] => stdClass Object ( [category] => Mercado Inmobiliario [id] => 3 ) [1] => stdClass Object ( [category] => Arquitectura [id] => 2 ) )
I've also included below the getPostCategories method in the Model:
Code:
function getPostCategories($post_id)
{
$suffix = '_' . $this->lang->lang();
$this->db->select("categories.category{$suffix} as category");
$this->db->select("categories.id");
$this->db->join('blog_categories_join', 'blog_categories_join.category_id = categories.id');
$this->db->where('blog_categories_join.blog_id', $post_id);
$result = $this->db->get('categories');
return $result->result();
}
Addendum
The view is the same is in your example:
Code:
<?php
if(!empty($post_categories[$post->id]))
{
foreach($post_categories[$post->id] as $category)
{
print_r($category->category);
}
}
?>