dty98339 2019-05-22 01:53
浏览 77

PHP - 动态添加复选框时如何自动递增值和名称

Good day! I would like to ask for help.

I'm currently making an Evaluation System for my school project. In my code, I can generate ALL the questions in my dbase together with 5 checkboxes.

e.g. If I add a new question to a particular criteria, it will be show to a table together with 5 auto-generated checkboxes.

how can I auto increment the name and value of my checkbox so if I save them to my dbase the value will be incremented every time there's a new question added?

I currently have 5 criterias, each have 5 questions and 5 sets of checkbox each. consisting of 25checkbox per criteria, but they have the same value and name when auto-generating.

<?php

        $sql = "SELECT * FROM question_pool_registrar WHERE criteria_id = 1";
        $result = $connect->query($sql);

        if($result->num_rows > 0){
            $nr = 0;
            while($row = $result->fetch_assoc()){
            $question = $row['question'];

                echo "<tr>
                <td>$question</td>
                <td><input type='checkbox' value=\"1c5".$nr."\" name=\"answer1".$nr."\" class='radio'></td>
                <td><input type='checkbox' value=\"1c4".$nr."\" name=\"answer1".$nr."\" class='radio'></td>
                <td><input type='checkbox' value=\"1c3".$nr."\" name=\"answer1".$nr."\" class='radio'></td>
                <td><input type='checkbox' value=\"1c2".$nr."\" name=\"answer1".$nr."\" class='radio'></td>
                <td><input type='checkbox' value=\"1c1".$nr."\" name=\"answer1".$nr."\" class='radio'></td>
                      </tr>";
                $nr++;
            }
        }

        ?>
  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 下图接收小电路,谁知道原理
    • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
    • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
    • ¥15 手机接入宽带网线,如何释放宽带全部速度
    • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
    • ¥15 ETLCloud 处理json多层级问题
    • ¥15 matlab中使用gurobi时报错
    • ¥15 这个主板怎么能扩出一两个sata口
    • ¥15 不是,这到底错哪儿了😭
    • ¥15 2020长安杯与连接网探