removing single quotes when using implode for comma seperated string of numbers |
[eluser]Otemu[/eluser]
Hi, Currently my query is returning as Code: AND `articles`.`categoryid` IN ('2,3,4,5') Code: AND `articles`.`categoryid` IN (2,3,4,5) currently my controller gets a list of ids in an array Code: $subcatids = $this->M_Categories->getSubCatIds($catid); Code: $commaCatIds = implode(',', $subcatids); Code: $this->db->where_in('articles.categoryid', $commaCatIds); How can I remove the single quotes or do I need to use another method to achieve this? Any help appreciated. Thanks
[eluser]Cristian Gilè[/eluser]
where_in accepts an array as second parameter. You can skip the implode statement.
[eluser]Otemu[/eluser]
[quote author="Cristian Gilè" date="1338835524"]where_in accepts an array as second parameter. You can skip the implode statement.[/quote] That wraps the array in single quotes for each number Code: AND `articles`.`categoryid` IN ('2', '3', '4', '5') How can I now remove them single quotes. Thanks
[eluser]Unknown[/eluser]
[quote author="Otemu" date="1338837030"][quote author="Cristian Gilè" date="1338835524"]where_in accepts an array as second parameter. You can skip the implode statement.[/quote] That wraps the array in single quotes for each number Code: AND `articles`.`categoryid` IN ('2', '3', '4', '5') How can I now remove them single quotes. Thanks[/quote] I ran into the sample problem. Here is my workaround for it: 1. Extend the Active Record class following instructions at http://mineth.net/blog/extending-codeign...hacky-way/ 2. The contents of my /application/core/MY_DB_active_rec.php file Code: public function where_in_int_array($key, $values) Code: $this->db->where_in('prof_functional_expertise', $arr); Code: $this->db->where_in_int_array('prof_functional_expertise', $arr); |
Welcome Guest, Not a member yet? Register Sign In |