Welcome Guest, Not a member yet? Register   Sign In
Please Help : num_rows() showing 0
#1

[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;
        }
    }


Messages In This Thread
Please Help : num_rows() showing 0 - by El Forum - 03-15-2009, 10:13 AM
Please Help : num_rows() showing 0 - by El Forum - 03-15-2009, 11:02 AM
Please Help : num_rows() showing 0 - by El Forum - 03-15-2009, 11:02 AM



Theme © iAndrew 2016 - Forum software by © MyBB