Welcome Guest, Not a member yet? Register   Sign In
Very stupid and elementary question
#1

[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?
#2

[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');

$where_in_string = implode(',', $selected_inst_ids);

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.
#3

[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)."'";
#4

[eluser]haydenk[/eluser]
well, if you're doing your inputs like this
Code:
<input type="checkbox" name="instrument[]" value="1" />
<input type="checkbox" name="instrument[]" value="2" />
<input type="checkbox" name="instrument[]" value="3" />
<input type="checkbox" name="instrument[]" value="4" />
then it's already putting it in an array for you, so implode is unnecessary as it takes a string and creates an array out of whatever you use as a separator.

Then you can create your own function to foreach() through the array and check if an id is in_array()
#5

[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.




Theme © iAndrew 2016 - Forum software by © MyBB