发布复选框值,即使未选中.(复选框的名称是数组格式)


Post checkbox value even if not checked. (Name of the checkbox is an array format )

我目前无法发布尚未选中并需要您帮助的复选框。以下是我当前使用的代码。

.PHP

while($select_info2 = mysqli_fetch_assoc($select_info1)){
$n='1';
echo "<tr>";
    echo "<td>".$select_info2['Device_DNS_name']."</td>";
    echo "<td>".$select_info2['Uplink_port']."</td>";
    echo "<td>".$select_info2['VLAN']."</td>";
    echo "<td>".$select_info2['Teamed_network']."</td>";
    echo "<td>".$select_info2['Teamed_description']."</td>";
    for($a = $select_detailed_dns2['starting_port']; $a <= $select_detailed_dns2['ending_port']; $a++ ){
        if('10' > $a){
            if ($select_info2["port-0".$a] == "1" || $select_info2["port-0".$a] == "01" ){
                $check ='checked="checked"';
            }else{
                $check = '';
            }
            ?>
                <td><input type="checkbox" name="check_<?php echo $select_info2['ID']."[]"?>" id="check_<?php echo $select_info2['ID']?>"  <?php echo $check ?> value = "On" /></td> 
            <?php
        }else{
            if ($select_info2["port-".$a] == "1" || $select_info2["port-".$a] == "1" ){
                $check ='checked="checked"';
            }else{
                $check = '';
            }
            ?>
                <td><input type="checkbox" name="check_<?php echo $select_info2['ID']."[]"?>" id="check_<?php echo $select_info2['ID']?>"  <?php echo $check ?> value = "On" /></td>
            <?php
        }
    }
    ?>
    <td><input type="button" name="Check_All" value="Check All" onClick="CheckAll(document.checktable.check_<?php echo $select_info2['ID']?>)"> </td>
    <td><input type="button" name="Un_Check_All" value="Uncheck All" onClick="UnCheckAll(document.checktable.check_<?php echo $select_info2['ID']?>)"> </td>
    <td><input type="submit" name="update_row" value="Update Row" > </td>
    <?php
echo "</tr>";   

}

上面的代码根据数据库中表中的列数生成复选框。您可能会问为什么名称是数组格式。这样我就可以发布所有值。您可能还会问为什么 id 相同而不是不同。这样我就可以定位整行进行检查或取消选中。以下是我目前输出所有选中复选框的方式:

<?php
if(isset($_POST['update_row'])){
    $c1 = $_POST['check_1'];
    var_dump($c1);
}

?>

生成的网页

<td><input type="checkbox" name="check_1[]" id="check_1"   value = "1"  /></td> 
                                                                                <td><input type="checkbox" name="check_1[]" id="check_1"   value = "1"  /></td> 
                                                                                <td><input type="checkbox" name="check_1[]" id="check_1"   value = "1"  /></td> 
                                                                                <td><input type="checkbox" name="check_1[]" id="check_1"   value = "1"  /></td> 
                                                                                <td><input type="checkbox" name="check_1[]" id="check_1"   value = "1"  /></td> 
                                                                                <td><input type="checkbox" name="check_1[]" id="check_1"   value = "1"  /></td> 
                                                                                <td><input type="checkbox" name="check_1[]" id="check_1"   value = "1"  /></td> 
                                                                                <td><input type="checkbox" name="check_1[]" id="check_1"   value = "1"  /></td> 
                                                                                <td><input type="checkbox" name="check_1[]" id="check_1"   value = "1"  /></td> 
                                                                                <td><input type="checkbox" name="check_1[]" id="check_1"   value = "1" /></td>
                                                                                <td><input type="checkbox" name="check_1[]" id="check_1"   value = "1" /></td>
                                                                                <td><input type="checkbox" name="check_1[]" id="check_1"   value = "1" /></td>
                                                                                <td><input type="checkbox" name="check_1[]" id="check_1"   value = "1" /></td>
                                                                                <td><input type="checkbox" name="check_1[]" id="check_1"   value = "1" /></td>
                                                                                <td><input type="checkbox" name="check_1[]" id="check_1"   value = "1" /></td>
                                                                                <td><input type="checkbox" name="check_1[]" id="check_1"   value = "1" /></td>
                                                                                <td><input type="checkbox" name="check_1[]" id="check_1"   value = "1" /></td>
                                                                                <td><input type="checkbox" name="check_1[]" id="check_1"   value = "1" /></td>
                                                                                <td><input type="checkbox" name="check_1[]" id="check_1"   value = "1" /></td>
                                                                                <td><input type="checkbox" name="check_1[]" id="check_1"   value = "1" /></td>
                                                                                <td><input type="checkbox" name="check_1[]" id="check_1"   value = "1" /></td>
                                                                                <td><input type="checkbox" name="check_1[]" id="check_1"   value = "1" /></td>
                                                                                <td><input type="checkbox" name="check_1[]" id="check_1"   value = "1" /></td>
                                                                                <td><input type="checkbox" name="check_1[]" id="check_1"   value = "1" /></td>
                                                                    <td><input type="button" name="Check_All" value="Check All" onClick="CheckAll(document.checktable.check_1)"> </td>
                            <td><input type="button" name="Un_Check_All" value="Uncheck All" onClick="UnCheckAll(document.checktable.check_1)"> </td>
                            <td><input type="submit" name="update_row" value="Update Row" > </td>
                            </tr><tr><td>HEPSAN03</td><td>No</td><td>NET44</td><td>No</td><td></td>                                         <td><input type="checkbox" name="check_2[]" id="check_2"   value = "1"  /></td> 
                                                                                <td><input type="checkbox" name="check_2[]" id="check_2"   value = "1"  /></td> 
                                                                                <td><input type="checkbox" name="check_2[]" id="check_2"   value = "1"  /></td> 
                                                                                <td><input type="checkbox" name="check_2[]" id="check_2"   value = "1"  /></td> 
                                                                                <td><input type="checkbox" name="check_2[]" id="check_2"   value = "1"  /></td> 
                                                                                <td><input type="checkbox" name="check_2[]" id="check_2"   value = "1"  /></td> 
                                                                                <td><input type="checkbox" name="check_2[]" id="check_2"   value = "1"  /></td> 
                                                                                <td><input type="checkbox" name="check_2[]" id="check_2"   value = "1"  /></td> 
                                                                                <td><input type="checkbox" name="check_2[]" id="check_2"   value = "1"  /></td> 
                                                                                <td><input type="checkbox" name="check_2[]" id="check_2"   value = "1" /></td>
                                                                                <td><input type="checkbox" name="check_2[]" id="check_2"   value = "1" /></td>
                                                                                <td><input type="checkbox" name="check_2[]" id="check_2"   value = "1" /></td>
                                                                                <td><input type="checkbox" name="check_2[]" id="check_2"   value = "1" /></td>
                                                                                <td><input type="checkbox" name="check_2[]" id="check_2"   value = "1" /></td>
                                                                                <td><input type="checkbox" name="check_2[]" id="check_2"   value = "1" /></td>
                                                                                <td><input type="checkbox" name="check_2[]" id="check_2"   value = "1" /></td>
                                                                                <td><input type="checkbox" name="check_2[]" id="check_2"   value = "1" /></td>
                                                                                <td><input type="checkbox" name="check_2[]" id="check_2"   value = "1" /></td>
                                                                                <td><input type="checkbox" name="check_2[]" id="check_2"   value = "1" /></td>
                                                                                <td><input type="checkbox" name="check_2[]" id="check_2"   value = "1" /></td>
                                                                                <td><input type="checkbox" name="check_2[]" id="check_2"   value = "1" /></td>
                                                                                <td><input type="checkbox" name="check_2[]" id="check_2"   value = "1" /></td>
                                                                                <td><input type="checkbox" name="check_2[]" id="check_2"   value = "1" /></td>
                                                                                <td><input type="checkbox" name="check_2[]" id="check_2"   value = "1" /></td>
                                                                    <td><input type="button" name="Check_All" value="Check All" onClick="CheckAll(document.checktable.check_2)"> </td>
                            <td><input type="button" name="Un_Check_All" value="Uncheck All" onClick="UnCheckAll(document.checktable.check_2)"> </td>
                            <td><input type="submit" name="update_row" value="Update Row" > </td>
                            </tr><tr><td>HEPSAN03</td><td>No</td><td>PRIV44</td><td>No</td><td></td>                                            <td><input type="checkbox" name="check_4[]" id="check_4"   value = "1"  /></td> 
                                                                                <td><input type="checkbox" name="check_4[]" id="check_4"   value = "1"  /></td> 
                                                                                <td><input type="checkbox" name="check_4[]" id="check_4"   value = "1"  /></td> 
                                                                                <td><input type="checkbox" name="check_4[]" id="check_4"   value = "1"  /></td> 
                                                                                <td><input type="checkbox" name="check_4[]" id="check_4"   value = "1"  /></td> 
                                                                                <td><input type="checkbox" name="check_4[]" id="check_4"   value = "1"  /></td> 
                                                                                <td><input type="checkbox" name="check_4[]" id="check_4"   value = "1"  /></td> 
                                                                                <td><input type="checkbox" name="check_4[]" id="check_4"   value = "1"  /></td> 
                                                                                <td><input type="checkbox" name="check_4[]" id="check_4"   value = "1"  /></td> 
                                                                                <td><input type="checkbox" name="check_4[]" id="check_4"   value = "1" /></td>
                                                                                <td><input type="checkbox" name="check_4[]" id="check_4"   value = "1" /></td>
                                                                                <td><input type="checkbox" name="check_4[]" id="check_4"   value = "1" /></td>
                                                                                <td><input type="checkbox" name="check_4[]" id="check_4"   value = "1" /></td>
                                                                                <td><input type="checkbox" name="check_4[]" id="check_4"   value = "1" /></td>
                                                                                <td><input type="checkbox" name="check_4[]" id="check_4"   value = "1" /></td>
                                                                                <td><input type="checkbox" name="check_4[]" id="check_4"   value = "1" /></td>
                                                                                <td><input type="checkbox" name="check_4[]" id="check_4"   value = "1" /></td>
                                                                                <td><input type="checkbox" name="check_4[]" id="check_4"   value = "1" /></td>
                                                                                <td><input type="checkbox" name="check_4[]" id="check_4"   value = "1" /></td>
                                                                                <td><input type="checkbox" name="check_4[]" id="check_4"   value = "1" /></td>
                                                                                <td><input type="checkbox" name="check_4[]" id="check_4"   value = "1" /></td>
                                                                                <td><input type="checkbox" name="check_4[]" id="check_4"   value = "1" /></td>
                                                                                <td><input type="checkbox" name="check_4[]" id="check_4"   value = "1" /></td>
                                                                                <td><input type="checkbox" name="check_4[]" id="check_4"   value = "1" /></td>
                                                                    <td><input type="button" name="Check_All" value="Check All" onClick="CheckAll(document.checktable.check_4)"> </td>
                            <td><input type="button" name="Un_Check_All" value="Uncheck All" onClick="UnCheckAll(document.checktable.check_4)"> </td>
                            <td><input type="submit" name="update_row" value="Update Row" > </td>
                            </tr><tr><td>HEPSAN03</td><td>No</td><td>NET40</td><td>No</td><td></td>                                         <td><input type="checkbox" name="check_5[]" id="check_5"   value = "1"  /></td> 
                                                                                <td><input type="checkbox" name="check_5[]" id="check_5"   value = "1"  /></td> 
                                                                                <td><input type="checkbox" name="check_5[]" id="check_5"   value = "1"  /></td> 
                                                                                <td><input type="checkbox" name="check_5[]" id="check_5"   value = "1"  /></td> 
                                                                                <td><input type="checkbox" name="check_5[]" id="check_5"   value = "1"  /></td> 
                                                                                <td><input type="checkbox" name="check_5[]" id="check_5"   value = "1"  /></td> 
                                                                                <td><input type="checkbox" name="check_5[]" id="check_5"   value = "1"  /></td> 
                                                                                <td><input type="checkbox" name="check_5[]" id="check_5"   value = "1"  /></td> 
                                                                                <td><input type="checkbox" name="check_5[]" id="check_5"   value = "1"  /></td> 
                                                                                <td><input type="checkbox" name="check_5[]" id="check_5"   value = "1" /></td>
                                                                                <td><input type="checkbox" name="check_5[]" id="check_5"   value = "1" /></td>
                                                                                <td><input type="checkbox" name="check_5[]" id="check_5"   value = "1" /></td>
                                                                                <td><input type="checkbox" name="check_5[]" id="check_5"   value = "1" /></td>
                                                                                <td><input type="checkbox" name="check_5[]" id="check_5"   value = "1" /></td>
                                                                                <td><input type="checkbox" name="check_5[]" id="check_5"   value = "1" /></td>
                                                                                <td><input type="checkbox" name="check_5[]" id="check_5"   value = "1" /></td>
                                                                                <td><input type="checkbox" name="check_5[]" id="check_5"   value = "1" /></td>
                                                                                <td><input type="checkbox" name="check_5[]" id="check_5"   value = "1" /></td>
                                                                                <td><input type="checkbox" name="check_5[]" id="check_5"   value = "1" /></td>
                                                                                <td><input type="checkbox" name="check_5[]" id="check_5"   value = "1" /></td>
                                                                                <td><input type="checkbox" name="check_5[]" id="check_5"   value = "1" /></td>
                                                                                <td><input type="checkbox" name="check_5[]" id="check_5"   value = "1" /></td>
                                                                                <td><input type="checkbox" name="check_5[]" id="check_5"   value = "1" /></td>
                                                                                <td><input type="checkbox" name="check_5[]" id="check_5"   value = "1" /></td>
                                                                    <td><input type="button" name="Check_All" value="Check All" onClick="CheckAll(document.checktable.check_5)"> </td>
                            <td><input type="button" name="Un_Check_All" value="Uncheck All" onClick="UnCheckAll(document.checktable.check_5)"> </td>
                            <td><input type="submit" name="update_row" value="Update Row" > </td>
                            </tr>

希望你能帮忙谢谢

您不能设置 default="0" 或 "2" 或其他东西并检查它吗?

也许这会有所帮助..发布未选中的复选框