【问题标题】:How to set the radio buttons for the attendance record PHP CSS?如何设置考勤记录的单选按钮 PHP CSS?
【发布时间】:2014-06-30 11:17:56
【问题描述】:

我想创建一个考勤记录表,老师可以记录学生的考勤情况并将其发送到数据库进行存储。在这里,我使用单选按钮,我希望这些按钮只选择存在或不存在或授权,但是现在它没有实现我想要做的事情。现在,单选按钮的选择无法正常工作,所以请我以特定方式放置单选按钮,以便它只选择存在或不存在或授权。我认为我们必须为这种 HTML 表单语法使用 CSS 或 javaScript,但问题是如何。先感谢您。

echo '<table action="process.php" method="POST" class="tableEchoPupilAttendance" border="1">
    <tr>
        <th>Image</th>
        <th>Name</th>
        <th>Present</th>
        <th>Absent</th>
        <th>Authorise</th>
    </tr>';

while($row = mysqli_fetch_array($result))
{
    echo "<tr>
        <td><img width='70' height='60' src='data:image/jpeg;base64,".base64_encode($row['image'])."'/></td>
        <td>" .$row['name']. $row['surname']."</td>
        <td> <input type='radio' name='present' value=''/>  </td>
        <td> <input type='radio' name='absent' value=''/>  </td>
        <td> <input type='radio' name='late' value=''/>  </td>
    </tr>";
}

echo "</table>";

【问题讨论】:

    标签: php html css styles structure


    【解决方案1】:

    单选按钮按name 属性分组。要让每一行的三个单选按钮中的一个可选,它们的names 必须相同,并且它们的所需值存储在value 属性中。

    我认为假设您的结果行中有某种id 是公平的。因此,以下代码可能会起作用:

    while ($row = mysqli_fetch_array($result)) {
        ?>
        <td><input type="radio" name="att[<?=$row['id'];?>]" value="present" /><td>
        <td><input type="radio" name="att[<?=$row['id'];?>]" value="absent" /><td>
        <td><input type="radio" name="att[<?=$row['id'];?>]" value="late" /><td>
        <?
    }
    

    提交它会给你一个包含如下内容的数组:

    [1] => 'present',
    [3] => 'absent',
    [4] => 'present',
    [6] => 'late'
    

    使用数值通常是个好主意,但代码可读性不强。

    【讨论】:

      【解决方案2】:

      只有同名的单选按钮才会被分组。所以你要做的是:

      <td> <input type='radio' name='attendance[<?php print $row['id']; ?>]' value='present'/>  </td>
      <td> <input type='radio' name='attendance[<?php print $row['id']; ?>]' value='absent'/>  </td>
      <td> <input type='radio' name='attendance[<?php print $row['id']; ?>]' value='late'/>  </td>
      

      【讨论】:

      • 只有一行数据时才有效。
      猜你喜欢
      • 2012-05-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-07-04
      • 1970-01-01
      • 2018-01-30
      • 2014-08-13
      • 2010-09-07
      相关资源
      最近更新 更多