PHP和MySQL的问题

When I delete a category that has been unchecked form the list of checkboxes the checkedbox remains checked until I leave the page and return to it again but I want the checkbox to be unchecked after it has been deleted when the user submits there changes. How can I do this?

Here is my PHP code.

for ($x = 0; $x < count($query_cat_id); $x++){
    if($query_cat_id[$x] == $cat['id']){
        echo 'checked="checked"';
    }

    if(isset($cat_id)){
        if(!in_array($query_cat_id[$x], $cat_id)){
            $mysqli = mysqli_connect("localhost", "root", "", "sitename");
            $delete_id = mysqli_query($mysqli,"DELETE FROM articles_categories WHERE article_id = '" . $article_id . "' AND category_id = '". $query_cat_id[$x] ."'");
            if (!$delete_id) {
                print mysqli_error($mysqli);
            }
        }
    }
}

It looks like you can check if your checkbox is destined for deletion, before setting it as checked:

if(($query_cat_id[$x] == $cat['id']) && ($cat['id'] != $delete_id)){
    echo 'checked="checked"';
}

Note how the if statement expression returns true only when $cat['id'] != $delete_id.

This is more than likely going to be rechecked by the browser. If you are not implicitly stating checked="checked", then the only thing you can do is write a JavaScript statement to uncheck it, and pray they don't have JavaScript turned off. Or rename the field.

Edit: I think I totally misread what you're saying. Still, leaving the answer just in case.