Php 无法禁用复选框

Php 无法禁用复选框,php,Php,我这里的问题是,只有当所有复选框状态为0时,我的复选框才会被禁用。但在这里,我只想禁用选中的复选框,但当复选框的状态未全部设置为0时,它将不会被禁用。 这是我的密码: <?php $username = $_SESSION['username']; $query = "SELECT * FROM box WHERE status = 1"; $result = @mysqli_query($con, $query); $num_rows = @mysqli_

我这里的问题是,只有当所有复选框状态为0时,我的复选框才会被禁用。但在这里,我只想禁用选中的复选框,但当复选框的状态未全部设置为0时,它将不会被禁用。 这是我的密码:

<?php
    $username = $_SESSION['username'];
    $query = "SELECT * FROM box WHERE status = 1";
    $result = @mysqli_query($con, $query);
    $num_rows = @mysqli_num_rows($result);
    $disable = '';
    if (!$num_rows) {
        $disable = 'disabled="disabled"';
    }    
?>

<form method = "post" action = "">    
    <input type='checkbox' name="boxs[]" id="1.1" value ="1.1" <?php echo $disable ?>/>
    <label for="1.1" class="background1"></label> <br/>
    <input type='checkbox' name="boxs[]" id="1.2" value ="1.2"<?php echo $disable ?>/>
    <label for="1.2" class="background2"></label> 
    <br/>
    <input type='checkbox' name="boxs[]" id="1.3" value ="1.3"<?php echo $disable ?>/>
    <label for="1.3" class="background2"></label> 
    <input type="submit" name="Next" id="Next" value="next" />
</form>
<?php    
    if(isset($_POST['Next'])) {   
        foreach($_POST['boxs'] as $f) {
            $sql = "UPDATE box SET status = '0' WHERE boxid = '$f'";
            mysqli_query($con,$sql) or die(mysqli_error($con));

            $result = "INSERT INTO booked(username, boxid) VALUES('$username', '$f')";
            mysqli_query($con,$result) or die(mysqli_error($con));
        }       
    }
?>

/>



我不知道你的确切要求,但是;您的解决方案可能是

<?php $username = $_SESSION['username']; ?>
<form method = "post" action = "">
<?php
$username = $_SESSION['username'];
$query = "SELECT * FROM box";
$result = @mysqli_query($con, $query);
$i=1;
while ($raw = $result->fetch_assoc()) {

    if ($raw['status'] == 1) {
        $disable = 'disabled="disabled"';
    } else {
        $disable = '';
    }
    echo "<input type='checkbox' name='boxs[]' id='" . $raw['boxid'] . "' value ='" . $raw['boxid'] . "' $disable/>";
    echo " <label for='" . $raw['boxid'] . "'  class='background$i'></label> <br/>";
 $i++;
}
?>
</form>


我查过你的密码了。但是找不到任何问题。那么,你有没有办法禁用复选框?我用你的代码检查过了。当零位通过时,所有复选框都将被禁用。当其他数字超过零时,复选框将启用。我没有发现任何错误。和我一样。我也面临着这种情况。请告诉我问题是什么。我的复选框有标签,所以每个都有不同的类别。请看修改后的答案。我想把我的复选框安排在3列中。我应该怎么做?该列需要看起来像tis:1.1 2.1 3.1
<?php $username = $_SESSION['username']; ?>
<form method = "post" action = "">
<?php
$username = $_SESSION['username'];
$query = "SELECT * FROM box";
$result = @mysqli_query($con, $query);
$i=1;
while ($raw = $result->fetch_assoc()) {

    if ($raw['status'] == 1) {
        $disable = 'disabled="disabled"';
    } else {
        $disable = '';
    }
    echo "<input type='checkbox' name='boxs[]' id='" . $raw['boxid'] . "' value ='" . $raw['boxid'] . "' $disable/>";
    echo " <label for='" . $raw['boxid'] . "'  class='background$i'></label> <br/>";
 $i++;
}
?>
</form>