Missing results using where_in |
[eluser]timpiele[/eluser]
I am running this very simple query against a 'products' table: Code: $ids = "1003,1005,1007,1009,1011,1013,1015,1017,1019,1021"; $this->db->last_query() shows me: Code: SELECT `id`, `title` FROM (`products`) WHERE `id` IN ('1003,1005,1007,1009,1011,1013,1015,1017,1019,1021') LIMIT 10 I have products in that table with ID's from 1001 through 1025, so they should return. print_r($query) gives me: Code: Array ( [0] => stdClass Object ( [id] => 1003 [title] => Vanilla ) ) Any thoughts on why it is just picking up the first item and that's it? I have tried single and double quoting each id in the $ids string, and putting double quotes inside of the IN() clause but I still get one result. if I comment out the where_in() clause I get the following, so I know the data is there: Code: Array
[eluser]Ckirk[/eluser]
I think it's because the where_in function is placing quotes around the $ids array There shouldn't be quotes in there for an array of numbers. I haven't tested it but try putting in the SQL yourself with quotes and then without. I'm fairly sure that's the problem. It's not the solution though [EDIT] quick search on google found someone else having a similar problem
[eluser]Ckirk[/eluser]
Actually the answer should be simpler than I first thought (it's nearly 3am here so am tired). It's not the where_in function that's putting quotes on it. It's you. change Code: $ids = "1003,1005,1007,1009,1011,1013,1015,1017,1019,1021"; to Code: $ids = array(1003,1005,1007,1009,1011,1013,1015,1017,1019,1021); That should solve it.
[eluser]Pert[/eluser]
If ids are stored as a string, you can also do Code: $ids_array = explode(',', $ids); |
Welcome Guest, Not a member yet? Register Sign In |