title: How to count the total Comments and total Likes using joined tables in codeigniter query
body: <p>I am attempting to get all of the posts inside my social media database.</p>
  
  <p>It's retrieve all list of post the user information, comments and likes.</p>
  
  <p>Now I have successfully retrieved the total comments of each post but having trouble counting all likes of each post.</p>
  
  <p>Here is my code so far.</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;?php
  
  public function get_all_post(){
  
    $category = $this-&gt;input-&gt;post('category', true);
    
    $this-&gt;db-&gt;select('u.*,c.parent_id,b.post_id, count(b.ID) as total, count(c.ID) as totalLIKEs');
    $this-&gt;db-&gt;where('u.category', $category);
    $this-&gt;db-&gt;order_by("u.create_at", "DESC")
    -&gt;from('gb_post as u')
    -&gt;join('gb_comments as b', 'u.ID = b.post_id', 'LEFT')
    -&gt;join('gb_likes as c', 'u.ID = c.parent_id', 'LEFT')
    -&gt;group_by('u.ID');
    
    $this-&gt;db-&gt;limit(10);
    $result = $this-&gt;db-&gt;get();
  
    if($result-&gt;num_rows() &gt; 0){
      return $result-&gt;result_array();
    } else {
      return false;
    }
  
  }
  ?&gt;</code></pre>
  </div>
  </div>
  </p>
  
  <p>Here is my SQL tables</p>
  
  <p>Post table</p>
  
  <pre><code>+----+---------------+-----------------+
  | ID | post_content  |   user_email    |
  +----+---------------+-----------------+
  |  1 | post1         | user1@email.com |
  |  2 | post2         | user2@email.com |
  |  3 | post3         | user3@email.com |
  +----+---------------+-----------------+
  </code></pre>
  
  <p>Comment Table</p>
  
  <pre><code>+----+---------+-----------------+-------------------+
  | ID | post_id | comment_content |   reader_email    |
  +----+---------+-----------------+-------------------+
  |  1 |       3 | test comment1   | reader1@email.com |
  |  2 |       3 | test comment2   | reader2@email.com |
  |  3 |       2 | test comment3   | reader3@email.com |
  |  4 |       1 | test comment4   | reader3@email.com |
  +----+---------+-----------------+-------------------+
  </code></pre>
  
  <p>And my Likes Table</p>
  
  <pre><code>+----+----------+-------------------+
  | ID | post_id  |   reader_email    |
  +----+----------+-------------------+
  |  1 |        3 | reader1@email.com |
  |  2 |        3 | reader2@email.com |
  |  3 |        3 | reader7@email.com |
  |  4 |        3 | reader3@email.com |
  +----+----------+-------------------+
  </code></pre>
  
  <p>Example the post with the ID of 3 will have a total of 2 comments and 4 likes.</p>
  
  <p>The problem is the count of <strong><code>totalComment</code></strong> is also the count of <strong><code>totalLIKEs</code></strong></p>