title: Codeigniter displaying total added likes from mysql table
body: <p>I am using MVC in codeigniter and I have a MySql table that has pages made by users <strong>page_id</strong> and topics <strong>topic_number</strong> as shown in the image below (Table page). pages can have multiple <strong>topic numbers</strong>.</p>
  
  <p>I also have another table called <strong>table page likes</strong> (shown in the image below also). This table also has <strong>page_id</strong> and <strong>topic_number</strong> but it has two more fields, which are, <strong>like</strong> and <strong>user_who_liked_topic_number</strong>.</p>
  
  <p><a href="https://i.stack.imgur.com/z4eEk.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/z4eEk.png" alt="enter image description here"></a></p>
  
  <p>My problem is that, I would like to display all the topic numbers that have or dont have likes. But if I only fetch topic numbers from the <strong>Table_page_likes</strong>, I will not get topic_numbers that dont have any likes recorded. which is why I am using both tables.</p>
  
  <p>The first table is fetched from the database where all the Topic_number is printed out. Then each Topic_number is searched in the <strong>table_pages_like</strong> to find if it has any like records and display it next to the Page_id and topic_number.</p>
  
  <p>This is my code so far, but I am not sure how to do the second step, which is to fetch each page_id with any number of likes from the table <strong>table_page_likes</strong> </p>
  
  <p><strong>controller_page.php</strong></p>
  
  <pre><code>     function viewdata() {
      $data['pages'] = $this-&gt;model_page-&gt;get_pages();
  
      $this-&gt;load-&gt;view('view_page', $data);
  
  
  }
  
  
  function get_like($post_id, $topic_number) {
  
      $data['liked_pages'] = $this-&gt;model_page-&gt;get_likes_model($post_id, topic_number);
  
      $this-&gt;load-&gt;view('view_page', $data);
  
  
  }
  </code></pre>
  
  <p><strong>model_page.php</strong></p>
  
  <pre><code>       function get_pages() {
  
      $query = $this-&gt;db-&gt;get_where('table_pages');
      return $query-&gt;result_array();
  
  }
  
   function get_likes($page_id, $topic_number) {
  
          $query = $this-&gt;db-&gt;get_where('table_pages_likes', array('page_id' =&gt; $page_id , 'topic_number' =&gt; $topic_number));
  
  }
  </code></pre>
  
  <p><strong>view_page.php</strong></p>
  
  <pre><code>              &lt;?php foreach($pages as $value): ?&gt;
        &lt;tr&gt;
          &lt;td&gt;&lt;?php echo $value['page_id']; ?&gt;&lt;/td&gt;
          &lt;td&gt;&lt;?php echo $value['topic_number']; ?&gt;&lt;/td&gt;
  
                  &lt;?php foreach($liked_pages as $value): ?&gt;
                      &lt;td&gt;&lt;?php echo $value['page_id']; ?&gt;&lt;/td&gt;
                      &lt;td&gt;&lt;?php echo $value['topic_number']; ?&gt;&lt;/td&gt;
                      &lt;td&gt;&lt;?php echo $value['like']; ?&gt;&lt;/td&gt;
                  &lt;?php endforeach; ?&gt;
        &lt;/tr&gt;
        &lt;?php endforeach; ?&gt;
  </code></pre>
  
  <p>Thanks in advance</p>