根据表中的值禁用或启用复选框

时间:2016-05-28 12:59:25

标签: php

如果$ partner的值为No,我想禁用checkPartner复选框 如果$ partner的值为Yes,我想启用checkPartner复选框
Grtz Benny

 <?php 

            $result3 = mysqli_query($con,"SELECT Partner, VIP FROM event WHERE eventID = ".$row['eventID']." ");
            while($row = mysqli_fetch_array($result, MYSQL_BOTH))  

                        $partner = $row['Partner'];

                            if ($partner = 'No') {

                            }
            ?>


                <form action="" method="post" name="RegisterForm1" id="RegisterForm1">
                <h6>Partner :<input type="checkbox" name="checkPartner"/>

1 个答案:

答案 0 :(得分:1)

您必须添加“禁用”属性。到html-element&#39;输入&#39;。 要根据条件做到这一点 - 在你的情况下 - 它会是这样的。

<?php
// inside your while-loop

$disabled = '';  // default
if ($partner == 'No') { // check the double == here!
    $disabled = "disabled";
}
?>

// then add that string-var to the html-element
<input type="checkbox" name="checkPartner" <?php echo $disabled ?>/>