=>Experimente este código, espero que seja útil.
//página html..
<label>Select State</label><br>
<?php
$allgroup = mysql_query("SELECT * FROM state");
$flag=false;
while($state_list = mysql_fetch_array($allgroup))
{
$parr=explode(',',$er['state_id']);
$size = sizeof($parr);
for($i=0;$i<$size;$i++) {
if($parr[$i]==$state_list['id']) {
$flag=true;
}
}
if($flag==true) {
?>
<input type='checkbox' name='state[]' style="margin-left:5px;" value="<?php echo $state_list['id']; ?>" checked > <?php echo $state_list['name']; ?> <br>
<?php
$flag=false;
} else {
?>
<input type='checkbox' name='state[]' style="margin-left:5px;" value="<?php echo $state_list['id']; ?>" > <?php echo $state_list['name']; ?> <br>
<?php
}
}
?>
// código php ..
<?php
$states="";
$i=0;
foreach( $_POST['state'] as $selected) {
echo sizeof($_POST['state']);
if($i==sizeof($_POST['state'])-1) {
$states = $states.$selected;
} else {
$states = $states.$selected.",";
}
$i++;
}
?>