title: codeigniter passing some id to display a comment count for a pasticular post
body: <p>i am building a simple blog posting and commenting following the <a href="http://codeigniter.com/tutorials/" rel="nofollow">codeigniter blog tutorial</a> instruction. Now i am trying to implement a facebook-wall-comment like on one page using jquery ajax, i have manage to do the wall post, and the comment post on each wall, also grouping the comments into its corresponding post, but i am having problem displaying the comment count for each wall, i am thinking like doing something like this </p>
  
  <p>Model: </p>
  
  <pre><code>function count_for_post($post_id){
      $query = $this-&gt;db-&gt;query("SELECT COUNT( id ) FROM comments WHERE post_id = ".$post_id);
      return $query; 
  }
  </code></pre>
  
  <p>Controller:</p>
  
  <pre><code>function comments(){
      $data['comment_query'] = $this-&gt;commentmodel-&gt;count_for_post($post_id);
      $this-&gt;load-&gt;view('content/post/comment_view', $data);
  }
  </code></pre>
  
  <p>how should i pass this <code>$post_id</code> parameters from  my view (all i can think of for now)</p>
  
  <p>since my post controller is this:</p>
  
  <pre><code>function index(){
      $data['post_query'] = $this-&gt;postmodel-&gt;get_desc();
      $this-&gt;load-&gt;view('content/postview', $data);
  }
  </code></pre>
  
  <p>and the only way i can fetch the particular id for each post is  by looping the <code>$post_query</code> in my view. </p>
  
  <p>i want to display something like</p>
  
  <pre><code>contents of Post 1
      contents of comment regarding post1
      contents of comment regarding post1
      contents of comment regarding post1
  
      view all count($this-&gt;commentmodel-&gt;count_for_post($post_id))
  
  contents of Post 2
      contents of comment regarding post2
      contents of comment regarding post2
      contents of comment regarding post2
  
      view all count($this-&gt;commentmodel-&gt;count_for_post($post_id2))
  
  contents of Post 3
      contents of comment regarding post3
      contents of comment regarding post3
      contents of comment regarding post3
  
      view all count($this-&gt;commentmodel-&gt;count_for_post($post_id3))
  </code></pre>
  
  <p>please help me on implementing the "best practice" way to do this, which is: what should i write on my model, my controller and my view.</p>
  
  <p>best regards</p>