Nirmal kumar
Nirmal kumar

Reputation: 65

How to pass a variable from controller to model in codeigniter?

Controller:

$this->data['students'] = $this->student_m->get_order_by_student_sattendance($id);

Model:

function get_order_by_student_sattendance($val) {
    $this->db->select()->from(student)->where('FIND_IN_SET($val, classesID)');
        $query = $this->db->get();
        return $query->result();
}

Hello, i just pass a variable $id to model as $val. But the result is Unknown column '$val' in 'where clause' SELECT * FROM student WHERE FIND_IN_SET($val, classesID). I think passing parameter is incorrect. Kindly suggest me the right code.

Thanks in advance

Upvotes: 0

Views: 546

Answers (2)

Dian Andria
Dian Andria

Reputation: 1

try this..change $id to $val

$this->data['students'] = $this->student_m->get_order_by_student_sattendance($val);

Upvotes: -1

parpar
parpar

Reputation: 339

if your are using single quote ('), you must use concatenation

->where('FIND_IN_SET(' . $val . ', classesID)');

OR use double qoute (")

->where("FIND_IN_SET($val, classesID)");

Upvotes: 4

Related Questions