database record fetch issue in codeigniter

2019-06-10 01:55发布

问题:

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

回答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



回答2:

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(); 

}