I have a form with add and edit function. Inside the form, they have checkboxes. The checkboxes itself is generated from mysql table.

When I want to do add function, the checkbox are populated correctly. However, I have issue when I entering edit function of the form.

I need the checkbox values are checked based when I do submit.

Here is my code:

**Controller:**

```
public function edit($id)
{
    $data['query'] = $this->Campaign_model->edit($id);
    $data['branch_list'] = $this->Campaign_model->get_branch_list();
    $data['branch_checked'] = $this->Campaign_model->get_checked_branches($id);

    $this->load->view('campaign_form', $data);
}

```

The `$data['branch_list']` contains the primary checkboxes. The `$data['branch_checked']` contains which checkboxes are checked within current data (query).

**View:**

```
$branch_id = "";

foreach($branch_list as $branch_list_checkbox)
{
    if($branch_list_checkbox->id == $branch_checked->branch_id)
    {
        $branch_id .= '<label><input name="branch_id[]" type="checkbox" value="'.$branch_list_checkbox->id.'" checked />'.$branch_list_checkbox->name.'</label>&nbsp;';
    }
    else
    {
        $branch_id .= '<label><input name="branch_id[]" type="checkbox" value="'.$branch_list_checkbox->id.'" />'.$branch_list_checkbox->name.'</label>&nbsp;';
    }           
}

```

Everything in `$branch_list` are populated properly. But how do I assign the `$branch_checked` properly to their respective checkboxes?

Need help, thanks.