[eluser]georgerobbo[/eluser]
Hello. I'm trying to display multiple categories assigned to a blog entry in CodeIgniter. I can do so with standard PHP but not CI.
Database Structure
table: Blog
BlogID
BlogSlug
BlogTitle
BlogContent
BlogPostDate
BlogAmmendDate
BlogThumb
BlogStatus
table: Category
CategoryID
The Category
table: BlogCategory
BlogID
CategoryID
In my controller I am successfully passing the 10 most recent blog entries to the view. What I want to achieve is for each entry to query all the categories assigned to that blog and then display them.
Controller: Home
Code:
<?php
class Home extends Controller {
function Home()
{
parent::Controller();
}
function index()
{
$this->load->model('Meta');
$this->load->model('Blog');
$this->load->helper('typography');
$this->load->library('excerpt');
$Data['GetLatest'] = $this->Blog->GetLatest();
$this->load->view('header',$Data);
$this->load->view('multiple');
$this->load->view('footer');
}
}
/* End of file Home.php */
/* Location: ./system/application/controllers/Home.php */
View: multiple
Code:
<div id="content">
<div class="wrapper">
<?php
foreach ($GetLatest->result_array() as $item)
{
?>
<div class="blog mini">
<div class="thumb">
<a href="<?php echo site_url('/blog/'.$item['BlogSlug']); ?>"><img src="<?php echo base_url(); ?>uploads/<?php echo $item['BlogThumb']; ?>" alt="<?php echo $item['BlogTitle']; ?>" /></a>
</div>
<h3><a href="<?php echo site_url('/blog/'.$item['BlogSlug']); ?>"><?php echo $item['BlogTitle']; ?></a></h3>
<p><a href="<?php echo site_url('/blog/'.$item['BlogSlug']); ?>"><?php echo $this->excerpt->construct($item['BlogContent']); ?></a></p>
</div>
<?php
}
?>
</div>
</div>