Checkbox values in array session as string

Asked

Viewed 56 times

1

I intend to join in a array the values of a checkbox but how string and so that they are separated by array('string1','string2'), to be able to use in a mysql query IN('string1','string2').

These values come from a checkbox to a session:

$variavel= $_SESSION['checkbox'] = implode(',',$_POST['checkbox']);

In this way, it separates only the values with ,, array(int1,int2), but when I put together a value string he makes a mistake.

How can I add ' to each value in the array to look like this array('string1','string2')?

1 answer

1

Well, I found a solution, which may not even be the most correct one, but it worked well through the value of the checkbox, where I just awarded the hiffen before and after the result.

If there is a more pro-active solution to this situation, I appreciate the help and/or clarification.

my checkbox:

<input name="chekcbox[]" type="checkbox" id="chekcbox" value="<?php echo "'".$linhaQueryMySql['campo']."'"; ?>" <?php if(strpos($variavel1,$linhaQueryMySql['campo'])!== false) echo 'checked="checked"'?> />

Browser other questions tagged

You are not signed in. Login or sign up in order to post.