[eluser]FutureKing[/eluser]
Code:
function check_term($term){
//checks whether a term is alreay present in term table
//if present then return term id or return false
$this->db->select('term_id,term');
$this->db->where('term',$term);
$query=$this->db->get('terms');
echo $query->num_rows(); // this is always showing 0
if($query->num_rows()>0){
foreach($query->result() as $row){
$termid=$row->term_id;
}
} else {
return false;
}
}
echo $query->num_rows(); is showing 0 everytime if check_term called from same model.
If I call this function from controller with by providing term. It works Fine.
But it is required to check_term called from same model.
Full programme is given below:
Code:
function insert_term($term){
$termid=$this->check_term($term);
if($termid==false){
$data = array(
'term' => $term ,
);
$this->db->insert('terms', $data);
} else {
$termid=$this->check_term($term);
}
return $termid;
}
function check_term($term){
//checks whether a term is alreay present in term table
//if present then return term id or return false
$this->db->select('term_id,term');
$this->db->where('term',$term);
$query=$this->db->get('terms');
echo $query->num_rows();
if($query->num_rows()>0){
foreach($query->result() as $row){
$termid=$row->term_id;
}
} else {
return false;
}
}