0

I have the problems using the array input as a value in WHERE clause.

But don't want to use more than once in WHERE clause code.

In my case, this is what I want :

$cond = array('job_id' => $job_id_var, 'job_name' => $job_name_var);
//WHERE clause
$this->where($cond); //only using once WHERE clause code like this, array as input
//which means
WHERE job_id = '$job_id_var' AND job_name = '$job_name_var'

is it possible to do that in codeigniter?

1
  • It is possible in codeIgniter. $this->db->where($cond); Commented Nov 11, 2014 at 3:04

1 Answer 1

2

Yes, the ->where() method can support that.

Since you do not want to cascade it:

$this->db->where('job_id', $job_id_var);
$this->db->where('job_name', $job_name_var);

->where() can handle array input as well:

$cond = array('job_id'=>$job_id_var, 'job_name'=>$job_name_var);

$this->db->where($cond); // here, only used once.

$query = $this->db->get('hello_table');
$result = $query->result_array();

return $result;
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.