Does get_where() allow multiple parameters?

I am passing a parameter from model to view like this

Model

class school_model extends CI_Model{

function employee_get($student_id){
$query = $this->db->get_where('students', array('student_id'=>$student_id));
return $query->row_array();
}

}

Controller

    function bret($student_id){
    $this->load->model('school_model');
    $data = $this->school_model->employee_get($student_id);
    echo $data['student_gender'];
    }

This obviously translates to select * from students where id=id given for example and seen through the browser like http://example.com/env/at/index.php/frontpage/bret/306

I am wondering if the get_where() is suitable if i wanted to have this query

select student_gender,student_has_a_medical_condition from students where (student_gender = 'female' && student_has_a_medical_condition = 'no') LIMIT 40;

Will i need to extend get_where() for it to work?.

Upvotes: 0

Views: 3681

Answers (1)

WoMo
WoMo

Reputation: 7266

First,I suggest reading the excellent documentation for CodeIgniter on the ActiveRecord class.

You don't have to extend get_where() but just use the existing methods to define your query:

function employee_get($student_id){
$this->db->select('student_gender','student_has_a_medical_condition');
$query = $this->db->get_where('students', array('student_id'=>$student_id,'student_has_a_medical_condition'=>'no','student_gender'=>'female'),40);
return $query->row_array();
}

Of course you can pass in the additional parameters to the function so they are not hardcoded, and you can also pass in the desired columns as a paremeter, too. But start with the documentation.

Upvotes: 2

Related Questions