复选框状态检查PHP

时间:2015-06-15 13:52:12

标签: php checkbox

当切换其他复选框时,如何选中其他复选框?

我的代码如下所示:

<form method="post"><input type="checkbox" name="checkall" value = "POST" />
</form>

<?php
    foreach($records as $r){
        if(isset($_POST["checkall"]) == 'POST'){
            $chc = "checked = 'checked'";
        }
        else{
            $chc = "";
        }
    }
?>

<form method="POST">
    <input type="checkbox" name="<?php echo escape($r->id); ?>" class="check" value="POST" <?php echo $chc ;?> />
</form>

代码没有用,任何人都可以帮助我。

非常感谢!

工作

1 个答案:

答案 0 :(得分:0)

...
   foreach($records as $r){    
                  if($_POST["checkall"] == 'POST')
                      {
                          ...

isset() function will tell you $_POST['checkall'] is there or not and also checks it has a value in it or not.

if you want to comapare $_POST['checkall'] with some value, you have to just compare like example above. If you want both, then use two if conditions like below

...
   foreach($records as $r)
   {    
              if(isset($_POST['checkall'])
              {
                  if($_POST["checkall"] == 'POST')
                      {
                          ...
                          ...
                      }
              }

That would help you. First of all, before putting up the codes, plan a structure of your page, what you have to do and what visitors have to do. WIthout plan, you will end up reaching nowhere and stuck. The code you have presented is not recommended.

If you put some more codes in your questions, we could help you to some extent.

相关问题