Tara Prasad Gurung
Tara Prasad Gurung

Reputation: 3559

Codeigniter not getting data though available in mysql database

I have a model which fetch the data from database is below

public function counselor() {
    $inst_id = $this->session->userdata('user_id');
    $submission_key=$this->session->userdata('submission_key');
    $query = $this->db->query("SELECT * FROM counselor where USER_ID = $inst_id AND submission_key= $submission_key");
    $data = $query->num_rows();
    if ($data > 0) {
        return $data;
    } else {
        return false;
    }
}

I have tested the $inst_id and $submission_key by printing it and its set. $inst_id=2 and $submission_key=2016-8 .BUT though I have one record in database with those two field set its not returning the data. What is the case. I have tried with codeigniter get() and where() method too. Still not giving me the result.

Upvotes: 1

Views: 164

Answers (1)

Saty
Saty

Reputation: 22532

Just write your query using active record function. It will help you in escaping string

 $this->db->select('*',FALSE);
    $this->db->where('USER_ID',$inst_id);
    $this->db->where('submission_key',$submission_key);
    $query=$this->db->get('counselor');
    $data = $query->num_rows();
    if ($data > 0) {
        return $data;
    } else {
        return false;
    }

Upvotes: 1

Related Questions