dongruoqiong9017 2016-10-30 11:25
浏览 53
已采纳

如何在PHP中设置单选按钮的值?

How do I set names for each radio button in the following PHP code using counter variable, or any other alternative?

<?php  

        $id=0; //counter variable 

        $sql ="select roll_number,student_name,gender from student_table";
        $query=mysqli_query($dbcon, $sql) or die(mysqli_error($dbcon));

          while($post=mysqli_fetch_assoc($query)){

             echo '<tr>';
            echo '<td>'. $post['roll_number'] . '</td>';
            echo '<td>'. $post['student_name'] . '</td>';
            echo '<td>'. $post['gender'] . '</td>';
            echo '<td width=250>';

            echo '<input type="radio" name="rad'.$id'" value="P" />Present';
            echo '<input type="radio" name="rad'.$id'" value="A" />Absent';

            echo '<button type="submit" name="save" value="Save" class="btn btn-success btn-sm">Save</button>';
            ++$id;
            echo '</td>';
            echo '</tr>';               

            }

           ?>
  • 写回答

2条回答 默认 最新

  • duanliang9288 2016-10-30 11:48
    关注
    echo '<input type="radio" name="rad[' . $post['roll_number'] . ']" value="P" />Present';
    echo '<input type="radio" name="rad[' . $post['roll_number'] . ']" value="A" />Absent';
    

    On the receiving end you may do like this:

    $answers = $_POST['rad'];
    foreach($answers as $roll_number=>$answer){
        //do something with the $roll_number and $answer...
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 乌班图ip地址配置及远程SSH
  • ¥15 怎么让点阵屏显示静态爱心,用keiluVision5写出让点阵屏显示静态爱心的代码,越快越好
  • ¥15 PSPICE制作一个加法器
  • ¥15 javaweb项目无法正常跳转
  • ¥15 VMBox虚拟机无法访问
  • ¥15 skd显示找不到头文件
  • ¥15 机器视觉中图片中长度与真实长度的关系
  • ¥15 fastreport table 怎么只让每页的最下面和最顶部有横线
  • ¥15 java 的protected权限 ,问题在注释里
  • ¥15 这个是哪里有问题啊?