According to me the thing which you are looking for is bit simple to do. you should use below mentioned code.
Code:
<form action="deleteUsers.php" method="post">
<div>
<input type="checkbox" name="delUsers[]" value='id1'/>User 1<br />
<input type="checkbox" name="delUsers[]" value='id2' />User 2<br />
<input type="checkbox" name="delUsers[]" value='id3' />User 3<br />
<input type="checkbox" onclick="selectAll(this)" />(un)check all<br />
<input type="submit" value="Delete users" />
</div>
</form>
<script>
function selectAll(elem){
var chkboxes = document.getElementsByName('delUsers[]');
for(i=0; i<chkboxes.length; i++){
chkboxes[i].checked = elem.checked;
}
}
</script>
After that you should build a query into the deleteUsers.php where you will be able to build your query so that you can process the passed userID by using below mentioned command.
Code:
<?php
if(isset($_POST['delUsers'])){
$str = implode(',',$_POST['delUsers']);
$query = 'delete from users where userID in('.$str.')';
echo $query;
//if all users were selected $query is
//delete from users where userID in(id1,id2,id3)
}
?>
If the user IDs are string then you should simply wrap them into $query.
Bookmarks