![]() |
Very stupid and elementary question - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20) +--- Forum: Archived General Discussion (https://forum.codeigniter.com/forumdisplay.php?fid=21) +--- Thread: Very stupid and elementary question (/showthread.php?tid=28031) |
Very stupid and elementary question - El Forum - 02-27-2010 [eluser]someoneinomaha[/eluser] Hello everyone. I apologize for this incredibly stupid question. I'm sure this has been answered below and it's just by feeble search ability today that is preventing me from finding the previous discussions. I have a set of checkboxes that I want to process to build a where in clause. So I get the array of items checked in the post and I need to loop through that to build a string of ids... like: '1', '2', '3' Is there an existing function to accomplish this, or do I need to loop through the array result, adding the formatting I want and omitting the last comma? Very stupid and elementary question - El Forum - 02-27-2010 [eluser]someoneinomaha[/eluser] So right now, I was using the following to build the string to pass to the where_in() method. Code: $selected_inst_ids = $this->input->post('instrument'); which returns: 2,1 Stupid? Is there another built in function I can use to product '2', '1' ? Or should I just create my own? Thank you. Very stupid and elementary question - El Forum - 02-27-2010 [eluser]ciGR[/eluser] If I understand your problem is that you want to create the '1','2' instead of 1,2 you get. Maybe you can try this Code: $where_in_string = "'". implode("','", $selected_inst_ids)."'"; Very stupid and elementary question - El Forum - 02-27-2010 [eluser]haydenk[/eluser] well, if you're doing your inputs like this Code: <input type="checkbox" name="instrument[]" value="1" /> Then you can create your own function to foreach() through the array and check if an id is in_array() Very stupid and elementary question - El Forum - 02-27-2010 [eluser]someoneinomaha[/eluser] I'm sorry for this thread... and wasting the time of anyone who had read this or took the time to post a reply. I had been flailing around trying to get the values from the check box and in my anger, made a simple syntax mistake, which led me down all sorts of paths because it didn't seem like I could just pass in the result array from the form post into the where_in() method... which I can. Yarg... It's working now. |