0

I am using a the following approach.

$param = $posts['cnv_post_id']; //$posts['cnv_post_id']holds the current post id 
$comments = $this->post_model->get_comments($param);

in model :-

public function get_comments($cnv_post_id) 
{
  $get_comments = 
           $this->db->query('select * from cnv_comment where blog_tbl='.$cnv_post_id.'');
   if($get_comments->num_rows > 0) 
   return $get_comments->result_array(); 

}

but its not giving the results. but if I explicitly give $param = '100' where 100 is the current post id. now, its returning the results

2
  • have you tried to run query it in phpmyadmin ? is it giving result ? Commented Jan 23, 2014 at 14:33
  • Your quoting in your query is wrong. Commented Jan 23, 2014 at 14:40

2 Answers 2

1

This is how you get the post from a form:

$param = $this->input->post('cnv_post_id');

Try outputing $this->db->last_query() and give it to us

Sign up to request clarification or add additional context in comments.

3 Comments

Sorry, it will sound funny but I am doing this on my view within php tag
so what is posts['cnv_post_id']? How do you get it?
see post is an array passed to a view posts[] has other data to show. I am just trying to fetch comment for every post.But is fetching null
0

You try it.

$param = $this->input->post('cnv_post_id'); //$posts['cnv_post_id']holds the current post id 
$comments = $this->post_model->get_comments($param);

public function get_comments($cnv_post_id) 
{
  $get_comments = 
           $this->db->query("select * from cnv_comment where blog_tbl = '$cnv_post_id'");
   if($get_comments->num_rows() > 0) 
      return $get_comments->result_array(); 

}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.