0

Is it possible to use codeigniter active records functions as an add on to the end of a regular sql statement? Something like this :

$sql = "SELECT * FROM test WHERE id = 'red'";
$this->db->WHERE_IN('code', $array);
$query = $this->db->get($sql);
return $query->result();

I really need the where_in function so i can apply an array of values, in which the number of values is constantly changing

Why do I want to do it this way instead of just doing it all in active records function? Because when I used just active records functions, I kept getting errors, and I don't want to spend more time smashing my head against the table in frustration.

2
  • 1
    Nope, as far as i know its not possible. implode() your array in a string and use a regular query. Commented Oct 23, 2013 at 15:22
  • You might be best to ask why you're getting the errors, as AR can be very useful to run your queries Commented Oct 23, 2013 at 15:31

1 Answer 1

1

Try like this:

$imploded_array  = implode(",", $array);
$sql = "SELECT * FROM test WHERE id = 'red' AND code IN ({$imploded_array})";
//$this->db->WHERE_IN('code', $array);
$query = $this->db->get($sql);
return $query->result();
Sign up to request clarification or add additional context in comments.

1 Comment

That worked, except when it hits ({$imploded_array}) its giving me (value,value), I need it to be ('value','value') or else i just get errors

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.