使用DB检查复选框

i've got n checkboxes. If one of them is checked user id and checkbox id are goin to DB . How can i save checkbox clicked after page reloading. Now i'm facing the problem in the cycle

for ($i = 0; $i < count($arr[3])); $i++){   // $arr - array containing user id and ckeckbox id    
          $active = "";
       if ($arr[3][$i]['id'] != ""){
          $active = "active" // class for active checkbox       

}
$checkbox .= "<div class="check_ '.$active.'"></div>";
}

for example if i've got 3 checkboxes and clicking on 1 and 3,an array will be like {1,3,NULL} instead of {1,NULL,3}. i think ckeckbox id should be equal to checkbox number

solved like this

for ($j=0; $j< count($array[3]); $j++){
        $mailing_list_id = $mailing_lists[3][$j]['id'];          
        $m_active = "";
        if(!empty($clicked[3])){ 
            for ($i=0;$i<count($result[3]);$i++){                
                if ($array[3][$j]['id'] == $clicked[3][$i]['id_usr_mailing_lists']){
                    $m_active = "active";
                } 
            }  
    $checkbox .= "<div class="check_ '.$active.'"></div>";


        }

where $arr contains all checkboxes and clicked contains clicked checkboxes

the trick is to make array of checkbox .. the html should look like :

 <form method='post' id='userform' action='thisform.php'> <tr>
        <td>Trouble Type</td>
        <td>
        <input type='checkbox' name='checkboxvar[]' value='Option One'>1<br>
        <input type='checkbox' name='checkboxvar[]' value='Option Two'>2<br>
        <input type='checkbox' name='checkboxvar[]' value='Option Three'>3
        </td> </tr> </table> <input type='submit' class='buttons'>
    </form>

and to read the from html

<?php 

    if (isset($_POST['checkboxvar'])) 
    {
        print_r($_POST['checkboxvar']); 
    }
?>

pay attention how to build this html according to your database ... i.e if a check box is selected it must be checked in the html ...

<