HTML 输入复选框通过 PHP 从 mysql 获取值

HTML input checkbox get value from mysql via PHP

如果 mysql 中的值为 1,如何设置复选框 nd 被选中?

<?php
    $select_PO=mysql_query("SELECT pono, nd, r, adj, no, am, ct, poyes, poyesp, pon FROM tb_po WHERE pono = '". $id ."' AND postatus !='Approved' AND pono NOT IN (SELECT pono FROM tb_postatus)", $conn);
    $count=mysql_num_rows($select_PO);

    if ($count == 1) {
        $row=mysql_fetch_array($select_PO);
        if ($row['nd'] = 1) {
            $nd="checked";
        }
        if ($row['r'] = 1) {
            $nd="checked";
        }
        mysql_close($conn);
?>
<input type="checkbox" id="nd" name="nd" checked="<?php echo $nd ?> "/>

HTML 复选框输入的属性 "checked" 是一个布尔值。这意味着它意味着复选框纯粹是通过存在来检查的。

<input type="checkbox" />                     <!-- Not checked -->
<input type="checkbox" checked />             <!-- checked -->
<input type="checkbox" checked="checked" />   <!-- checked -->

checked 属性的值是什么并不重要,即使它有一个也不重要。属性的存在意味着复选框被选中。

看看这个,

<?php
    $select_PO=mysql_query("SELECT pono, nd, r, adj, no, am, ct, poyes, poyesp, pon FROM tb_po WHERE pono = '". $id ."' AND postatus !='Approved' AND pono NOT IN (SELECT pono FROM tb_postatus)", $conn);
    $count=mysql_num_rows($select_PO);

    if ($count == 1) {
        $row=mysql_fetch_array($select_PO);
        if ($row['nd'] = 1) {
            $nd="checked";
        }
        if ($row['r'] = 1) {
            $nd="checked";
        }
        mysql_close($conn);
?>
<input type="checkbox" id="nd" name="nd" <?php echo $nd ?> />