removing single quotes when using implode for comma seperated string of numbers - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20) +--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23) +--- Thread: removing single quotes when using implode for comma seperated string of numbers (/showthread.php?tid=52276) |
removing single quotes when using implode for comma seperated string of numbers - El Forum - 06-04-2012 [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 removing single quotes when using implode for comma seperated string of numbers - El Forum - 06-04-2012 [eluser]Cristian Gilè[/eluser] where_in accepts an array as second parameter. You can skip the implode statement. removing single quotes when using implode for comma seperated string of numbers - El Forum - 06-04-2012 [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 removing single quotes when using implode for comma seperated string of numbers - El Forum - 09-19-2012 [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-codeigniter-active-record-the-non-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); |