Kevin
Kevin

Reputation: 23634

Getting the ID's of all selected field in php

When i select multiple checkbox, i get the values something like this....

9,[email protected],1,9,[email protected],2,2,[email protected],3,2,[email protected],4

Now i need to delete all of them, so i need to pass their user ID alone to query. For this i need to split the string and pass their multiple ID's alone to query.

    $var1 = $theArrayValue;
$chan= explode(',', $var1);
return $chan;

$theArrayValue holds all these info below.

9,[email protected],1,9,[email protected],2,2,[email protected],3,2,[email protected],4

I need to delete multiple items selected.

Upvotes: 0

Views: 130

Answers (2)

Markus Hedlund
Markus Hedlund

Reputation: 24284

To clarify the answer above

<form action="" method="post">

<input type="checkbox" name="myfield[]" value="1" />
<input type="checkbox" name="myfield[]" value="2" />
<input type="checkbox" name="myfield[]" value="3" />

<input type="submit" />

</form>

If you vardump the $_POST variable from PHP, you will get the following output.

array(1) { ["myfield"]=>  array(2) { [0]=>  string(1) "1" [1]=>  string(1) "3" } } 

In this example I selected value 1 and 3. The value of the checkbox should be the id.

Upvotes: 1

ErsatzRyan
ErsatzRyan

Reputation: 3043

name your field name="myfield[]" then it will come to php in an array

Upvotes: 4

Related Questions