Php 如何计算while循环中未选中的复选框 $query=mysql\u query(“从tbl\u软件安装中选择不同的状态,供应商不喜欢“”); $nums=mysql\u num\u行($query); 回声“ $nums 软件供应商”; $ctr1=1; while($fetch=mysql\u fetch\u数组($query)){ $vendor=$fetch['vendor']; $status=$fetch['status']; 如果($ctr1%2)=1) {打印“”;} 其他的 {打印“”;} “打印” $vendor} 否则{ 打印“>$vendor”;} $ctr1++; } 打印“”; “打印” "; $submit=$_POST['submit']; 如果(isset($submit)) { $chk=$_POST['chk']; $count=计数($chk); 如果(空($chk)){ 回声“qweqwe”; } 对于($i=0;$i

Php 如何计算while循环中未选中的复选框 $query=mysql\u query(“从tbl\u软件安装中选择不同的状态,供应商不喜欢“”); $nums=mysql\u num\u行($query); 回声“ $nums 软件供应商”; $ctr1=1; while($fetch=mysql\u fetch\u数组($query)){ $vendor=$fetch['vendor']; $status=$fetch['status']; 如果($ctr1%2)=1) {打印“”;} 其他的 {打印“”;} “打印” $vendor} 否则{ 打印“>$vendor”;} $ctr1++; } 打印“”; “打印” "; $submit=$_POST['submit']; 如果(isset($submit)) { $chk=$_POST['chk']; $count=计数($chk); 如果(空($chk)){ 回声“qweqwe”; } 对于($i=0;$i,php,mysql,Php,Mysql,浏览器只会告诉您哪些框已选中。从数据库中拉出所有可能的框,然后删除浏览器告诉您已选中的框。我也做过类似的事情,计算未选中的框。 将输入类型为复选框和输入类型的两个输入字段以不同的名称隐藏 $query = mysql_query("SELECT DISTINCT status, vendor FROM tbl_softwareinstalled WHERE vendor NOT LIKE ''"); $nums = mysql_num_rows($query); echo "<form n

浏览器只会告诉您哪些框已选中。从数据库中拉出所有可能的框,然后删除浏览器告诉您已选中的框。

我也做过类似的事情,计算未选中的框。 将输入类型为复选框和输入类型的两个输入字段以不同的名称隐藏

$query = mysql_query("SELECT DISTINCT status, vendor FROM tbl_softwareinstalled WHERE vendor NOT LIKE ''");
$nums = mysql_num_rows($query);
echo "<form name = 'filter' action='softwarefilter.php' method='POST'>
$nums<br>

<table border = 1><tr><td>&nbsp;</td>
<td><strong>Software Vendor</strong></td></tr>";

$ctr1 = 1;
while($fetch = mysql_fetch_array($query)) {
$vendor = $fetch['vendor'];
$status = $fetch['status'];
    if(($ctr1 % 2)==1)
        { print "<tr bgcolor = 'white'>";}
        else 
        { print "<tr bgcolor = '#EEEEEE'>"; }
    print "<td><input name= 'chk[]' type='hidden' value='0'>
    <input type = 'checkbox' name = 'chk[]' value = '$vendor' ";




    if ($status == 'Enabled') {
    print "checked = 'checked'></td><td>$vendor</td></tr>"; }
    else {
    print "></td><td>$vendor</td></tr>"; }
    $ctr1++;
}
print "</table>";
print "<input type = 'submit' name = 'submit' value = 'Update Filter'>
</form> ";


$submit = $_POST['submit'];
if(isset($submit))
{ 
    $chk = $_POST['chk'];
    $count = count($chk);

    if (empty($chk)) {

    echo "qweqwe<br>";
    }

        for ($i=0; $i<$count; $i++) {
        $abc = $chk[$i];
        $query = mysql_query("UPDATE tbl_softwareinstalled SET status = 'Enabled' WHERE vendor = '$abc'");

        }

    echo '<meta http-equiv="refresh" content="0.5;url=/assets/softwarefilter.php">
            <script language="javascript">
            alert("Software filter updated.");
            </script>';
}
对于您的情况,请将此更改为:

if (isset($_POST['submit'])) {
    $cnt = array();
    $counter =0;
    $testcnt = 0;
    $cnt = 0;
    if (isset($_POST['test'])) {
        $testcnt = count($_POST['test']);
    }
    if (isset($_POST['checkbox'])) {
        $cnt = count($_POST['checkbox']);
    }
    echo 'the count of unchecked boxes is ';
    print_r($testcnt-$cnt);
}
if (isset($_POST['submit'])) {
    $cnt = array();
    $counter =0;
    $testcnt = 0;
    $cnt = 0;
    if (isset($_POST['test'])) {
        $testcnt = count($_POST['test']);
    }
    if (isset($_POST['checkbox'])) {
        $cnt = count($_POST['checkbox']);
    }
    echo 'the count of unchecked boxes is ';
    print_r($testcnt-$cnt);
}
<input name= 'unchecked[]' type='hidden' value='0'>
$unchecked_input = count($_POST['unchecked']);
$chk = $_POST['chk'];
$count = count($chk);
echo $unchecked_input-$count; //will output the count of unchecked boxes