title: How do i display category for each post in codeigniter
body: <p>I want to display category to each of my posts. Through tutorials, I was able to create <code>MY_Model</code>, but i am unable to display category on each post.</p>
  
  <p>This is my post model:</p>
  
  <pre><code>&lt;?php
  class Post_m extends MY_Model
  {
      protected $_table_name = 'posts';
      protected $_order_by = 'pubdate desc, id desc';
      protected $_timestamps = TRUE;
      public $rules = array(
          'pubdate' =&gt; array(
              'field' =&gt; 'pubdate',
              'label' =&gt; 'Publication date',
              'rules' =&gt; 'trim|required|exact_length[10]'
          ),
          'title' =&gt; array(
              'field' =&gt; 'title',
              'label' =&gt; 'Title',
              'rules' =&gt; 'trim|required|max_length[100]'
          ),
          'slug' =&gt; array(
              'field' =&gt; 'slug',
              'label' =&gt; 'Slug',
              'rules' =&gt; 'trim|required|max_length[100]|url_title'
          ),
          'body' =&gt; array(
              'field' =&gt; 'body',
              'label' =&gt; 'Body',
              'rules' =&gt; 'trim|required'
          )
      );
  
      public function get_new ()
      {
          $post = new stdClass();
          $post-&gt;title = '';
          $post-&gt;slug = '';
          $post-&gt;body = '';
          $post-&gt;name = '';
          $post-&gt;post_image = '';
          $post-&gt;pubdate = date('Y-m-d');
          return $post;
      }
  
      public function set_published(){
          $this-&gt;db-&gt;where('pubdate &lt;=', date('Y-m-d'));
      }
  
      public function get_recent($limit = 3){
  
          // Fetch a limited number of recent articles
          $limit = (int) $limit;
          $this-&gt;set_published();
          $this-&gt;db-&gt;limit($limit);
          return parent::get();
      }
  
      public function get_categories()
      {
          $this-&gt;db-&gt;order_by('name');
          $query = $this-&gt;db-&gt;get('categories');
          return $query-&gt;result_array();
      }
  
  }
  ?&gt;
  </code></pre>
  
  <p>Now I want to display the category by name. This is what I have so far:</p>
  
  <pre><code>&lt;div class="table-responsive"&gt;
      &lt;table class="table table-striped table-sm"&gt;
          &lt;thead&gt;
          &lt;tr&gt;
              &lt;th&gt;#&lt;/th&gt;
              &lt;th&gt;Title&lt;/th&gt;
              &lt;th&gt;Posts&lt;/th&gt;
              &lt;th&gt;Category&lt;/th&gt;
              &lt;th&gt;Date&lt;/th&gt;
              &lt;th&gt;&lt;/th&gt;
          &lt;/tr&gt;
          &lt;/thead&gt;
          &lt;tbody&gt;
          &lt;?php if(count($posts)): foreach ($posts as $key =&gt; $post)  if ($key &gt;= 1) { ?&gt;
          &lt;tr&gt;
              &lt;td&gt;&lt;?php echo $key; ?&gt;&lt;/td&gt;
              &lt;td&gt;&lt;?php echo anchor('admin/posts/edit/' . $post-&gt;id, $post-&gt;title); ?&gt;&lt;/td&gt;
              &lt;td&gt;&lt;?php echo e(limit_to_numwords(strip_tags($post-&gt;body), 10)); ?&gt;&lt;/td&gt;
              &lt;td&gt;&lt;?php echo $post-&gt;category_id; ?&gt;&lt;/td&gt;
              &lt;td&gt;&lt;?php echo $post-&gt;pubdate; ?&gt;&lt;/td&gt;
              &lt;td&gt;&lt;?php echo btn_edit('admin/posts/edit/' . $post-&gt;id); ?&gt;&lt;/td&gt;
              &lt;td&gt;&lt;?php echo btn_delete('admin/posts/delete/' . $post-&gt;id); ?&gt;&lt;/td&gt;
          &lt;/tr&gt;
          &lt;?php } ?&gt;
          &lt;?php else: ?&gt;
          &lt;tr&gt;
              &lt;td class="center" colspan="3"&gt;We could not find any articles.&lt;/td&gt;
          &lt;/tr&gt;
          &lt;?php endif; ?&gt;
          &lt;/tbody&gt;
      &lt;/table&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p>If you notice, I added <code>$post-&gt;category_id</code>, but it only displays INT and not the name of the category.</p>
  
  <p>Please, help!!</p>