douweibiao8471 2018-09-25 02:38
浏览 74

如何使用复选框列表验证测试?

I have a checkbox list with 10 options ik the image just have 9:

and a db:

How can I compare the input in the checkbox list with the information inside the column requerimientos in my db?, it means values from the checkbox list must contain all of the values from requerimientos and it will happen with every id, just i didn't fill the other values yet, hope this clarify it

This is what I got, if it seems I have no clue what I am doing it can't be more accurate, but I dont give up. XD

<form action="" method="post">
    <?php
        $query = $mysqli->query("SELECT idclasificacion,clasificacion FROM clasificacion");
        while ($rows = $query->fetch_array()) {
            echo'<div class="list-group-item"  id='. $rows['idclasificacion'] .'>
                <label>
                    <input type="checkbox" name="requerimiento[]" id="" value="'.$rows['clasificacion'].'">'. $rows['clasificacion'] . '
                </label>
            </div>';
        }
    ?>
    <button class="btn btn-primary" type="submit">Ingresar</button>
</form>


<?php            
    //extrae los requerimiento seleccionados en forma de string, notar que requerimiento va sin []
    if (isset($_POST['requerimiento'])){                
        $requerimientos = implode ( ',', $_POST['requerimiento']);
        echo $requerimientos;
    }else {
        echo'no ha selecionado ningun requerimiento para su evento';
    }        

    echo '<br>';            

    $query = $mysqli->query("SELECT requerimientos FROM tipologia");
    $rows = $query->fetch_assoc();            
    var_dump($rows);
    $requetipo=explode(',', $rows['requerimientos']);
    var_dump($requetipo);
    $validacion=in_array($requerimientos,$requetipo);
    var_dump ($validacion);                        
?>
  • 写回答

1条回答 默认 最新

  • doujugu1722 2018-09-26 00:37
    关注

    tthis code compare the checked options, with the data inside requerimientos and if both are equal returns true if not false.

    Now i just need to do the other options hope a for loop will help me XD

    <?php            
                //extrae los requerimiento seleccionados en forma de string, notar que requerimiento va sin []
                if (isset($_POST['requerimiento'])){                
                    $requerimientos = implode ( ',', $_POST['requerimiento']);
                       // echo $requerimientos;
                }else {
                    echo'no ha selecionado ningun requerimiento para su evento';
                }        
                
                echo '<br>';            
    
                $query = $mysqli->query("SELECT requerimientos FROM tipologia where tipologia='Conferencia'");
                $rows = $query->fetch_assoc();
                if($requerimientos==$rows['requerimientos']){
    echo 'right';
    }else{
        echo 'wrong';
    }

    </div>
    
    评论

报告相同问题?

悬赏问题

  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥15 c++头文件不能识别CDialog
  • ¥15 Excel发现不可读取的内容