title: Pulling data from database in CodeIgniter ( or any MVC platform)?
body: <p>I have this in Model:</p>
  
  <pre><code>public function index_loop() { 
          $post_user = $this-&gt;db-&gt;query("SELECT posts.post_title, posts.post_content, posts.post_date, users.username FROM posts LEFT JOIN users ON posts.user_id = users.user_id ORDER BY posts.post_ID DESC");
          //$categories = $this-&gt;db-&gt;query("SELECT categories.cat_name, categories.cat_id FROM  
          //$comments = $this-&gt;db-&gt;query("SELECT COUNT(comment_id) FROM comments WHERE
          return $post_user-&gt;result_array();
      }
  </code></pre>
  
  <p>What I need is to show categories for each post and comments (although I guess if I figure out categories passing than comments are the same way)</p>
  
  <p>in View file: </p>
  
  <pre><code> &lt;?php foreach($posts as $zz) { ?&gt;
           &lt;div class="article"&gt;
             &lt;h2&gt;&lt;?php echo $zz['post_title']; ?&gt;&lt;/h2&gt;
             &lt;p&gt;Posted by &lt;a href=""&gt;&lt;?php echo $zz['username']; ?&gt;&lt;/a&gt; | Filed under &lt;a href="#"&gt;templates&lt;/a&gt;, &lt;a href=&gt;internet&lt;/a&gt;&lt;/p&gt;
              &lt;p&gt;&lt;?php echo $zz['post_content']; ?&gt;&lt;/p&gt;
             &lt;p&gt;&lt;a href=&gt;Read more&lt;/a&gt; | &lt;a href=&gt;Comments (5)&lt;/a&gt; | &lt;?php echo $zz['post_date']; ?&gt;&lt;/p&gt;
          &lt;/div&gt; &lt;?php } ?&gt;
  </code></pre>
  
  <p>So, if I want to loop categories on each blog I need that blogs ID, how do I get it if I make all queries from Model? 
  The same for comments</p>
  
  <p>Is it good that I make one big complicated DB query ( which is hard but I can do it) or I can do 2 or 3 separate smaller queries?</p>