Reputation: 674
$code = Array(1,2,3,4)
$sql = "SELECT * FROM Table1 WHERE Field1 IN (?)";
$query = $this->db->query($sql, array($code));
$this->db->last_query()
will show
"SELECT * FROM Table1 WHERE Field1 IN ('1,2,3,4')"
How can I remove the single quote in the IN condition?
Even if the $code
is array of strings, example
$code = Array('This one', 'Next code', 'And this')
the statement will be:
"SELECT * FROM Table1 WHERE Field1 IN ('This one, Next Code, And This')"
Am I missing something ?
TIA.
Upvotes: 1
Views: 1041
Reputation: 1108
From codeigniter active record manual
$this->db->where() accepts an optional third parameter. If you set it to FALSE, CodeIgniter will not try to protect your field or table names with backticks.
$this->db->where('MATCH (field) AGAINST ("value")', NULL, FALSE);
So, put a 3rd parameter on a where clause with FALSE
Then your query should be
$this->db->select('*')
->where('Field1 IN('.$code.'),NULL,FALSE)
->get('Table1');
Upvotes: 1
Reputation: 19882
You can use this simple and alternate way
$this->db->where_in('Field1',$code);
$this->db->get('Table1');
Upvotes: 3