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.

4

1 回答 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();
于 2013-10-23T15:25:55.473 回答