【问题标题】:HTML Table and CheckboxesHTML 表格和复选框
【发布时间】:2016-02-10 01:37:58
【问题描述】:

我有 1 个表格,里面有复选框.. 我想要发生的是将复选框的值设置为 student_id

这是我的代码:

      <?php 
        require_once('xcon.php'); 
        $q = mysql_query("SELECT * FROM Students");
      ?>

      <table><br><br>
            <thead>
                <tr>
                    <th>Choice</th>
                    <th>Student ID</th>
                    <th>Student First Name</th>
                    <th>Student Last Name</th>
                    <th>Level</th>
                </tr>
            </thead>
            <?php
                 while($row = mysql_fetch_assoc($q)){

                    echo "<tbody>";    
                    echo "<tr>";
                    echo "<td><input type = 'checkbox' name = 'checkbox[]' ></td>";
                    echo "<td>".$row['student_id']."</td>";
                    echo "<td>".$row['fname']."</td>";
                    echo "<td>".$row['lname']."</td>";
                    echo "<td>".$row['yearlevel']."</td>";
                    echo "</tr>";
                    echo "</tbody>";
                }  
            ?> 

    </table>

我似乎很难理解其中的逻辑,我很困惑。

提前感谢您的帮助。

【问题讨论】:

    标签: php html checkbox html-table


    【解决方案1】:
    echo "<td><input type = 'checkbox' name = 'checkbox[]' value='{$row['student_id']}'></td>";
    

    【讨论】:

    • 请给你的答案添加一些解释!
    【解决方案2】:

    value 属性添加到您的复选框,其值为学生ID:

    while($row = mysql_fetch_assoc($q)){
    
        echo "<tbody>";    
        echo "<tr>";
        echo "<td><input type = 'checkbox' name = 'checkbox[]' value='".$row['student_id']."'></td>";
        echo "<td>".$row['student_id']."</td>";
        echo "<td>".$row['fname']."</td>";
        echo "<td>".$row['lname']."</td>";
        echo "<td>".$row['yearlevel']."</td>";
        echo "</tr>";
        echo "</tbody>";
    }
    

    值得注意的是复选框的值只有在复选框被选中时才会发布到表单的目标。

    【讨论】:

    • 这就是我的意思..如果复选框被选中,我想要标记的值..感谢您的帮助:)
    • 没问题,很高兴我能提供帮助。
    【解决方案3】:

    我认为您正在查看如下。将值属性添加到复选框输入字段,值应为 $row['student_id']。

    <?php
                     while($row = mysql_fetch_assoc($q)){
    
                        echo "<tbody>";    
                        echo "<tr>";
                        echo "<td><input type = 'checkbox' name = 'checkbox[]' value='".$row['student_id']."' ></td>";
                        echo "<td>".$row['student_id']."</td>";
                        echo "<td>".$row['fname']."</td>";
                        echo "<td>".$row['lname']."</td>";
                        echo "<td>".$row['yearlevel']."</td>";
                        echo "</tr>";
                        echo "</tbody>";
                    }  
                ?> 
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-08-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-02-13
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多