I'm newbie for codeigniter & PHP. need some help.
I've a trouble when trying to show my blog post into the blog view.
Table :
blog category blog_category | ------- | | -------- | | ------------- | | blog_id | | cat_id | | cat_id | | title | | cat_name | | blog_id | | content | | cat_slug |
in my blog controllers :
defined('BASEPATH') OR exit('No direct script access allowed');
class Blog extends CI_Controller {
    /*
     * Blog Controller
     */
    public function __construct()
    {
        parent::__construct();
        $this->load->model('blog_model');
    }
    public function index()
    {
        $this->data = array(
            'title' => 'Blog',
            'blog' => $this->blog_model->get_all_post(),
        );
        $this->load->view('main/blog', $this->data);
    }
}
and in my blog model :
function get_all_post() {
    $this->db->select('*');
    $this->db->from('blog');
    $this->db->join('blog_category', 'blog_category.blog_id=blog.blog_id', 'left');
    $this->db->join('category', 'blog_category.cat_id=category.cat_id');
    $query = $this->db->get();
    $select = array();
    foreach($query->result() as $row) {
        $select[] = $row;
    }
    if (count($select) > 0)
        return $select;
    return NULL;
}
and in my blog view :
<?php foreach ($blog as $item): ?>
<h3 class="post-title"><a href="#"><?php echo $item->title;?></a></h3>
<p class="category"><?php echo $item->categories;?></p>
<?php endforeach;?>
and when I try to access the view, it's show 2 Post with a same Record but with different categories. In my blog post have a 2 categories and show one by one, if in my post have 3 categories then result show 3 post with 3 categories show one by one. sorry for my bad english.
 
    