duanjiaoxi4928 2019-05-09 07:46
浏览 223

如何通过复选框选择表中的多行,并将这些值传递给另一个表

I want to select multiple rows in a table via checkboxes and store these values in another table.I have almost done. But problem is that when I select multiple rows and get these values via array. It only fetch single value. I want all selected values. Please help me in this regard. My code is given below.

<form class="form-horizontal" method="post" action="add_exam_quiz.php" role="form" id="form1">
  <tr>
    <td>
      <input type="checkbox" name="quiz_question[<?php echo  $question_no; ?>]" value="<?php echo  $question_no; ?>">
      <?php echo  $question_no; ?> 
    </td>
</form>
</tr>

<input class="btn btn-primary" type="submit" name="submit" value="submit" form="form1">

I expect an array with all checked values. But I got single value.

  • 写回答

2条回答 默认 最新

  • dtu11716 2019-05-09 07:57
    关注

    You need to have all the checkboxes with the same name like this:

    <td><input type="checkbox" name="quiz_question[]" value="<?php echo  $question_no; ?>"> <?php echo  $question_no; ?> </td>
    

    then in PHP:

    <?php
    
       $quiz_question = $_POST['quiz_question'];
    
       foreach ($quiz_question as $question=>$value) {
                 echo $value."<br />";
            }
    
    ?>
    
    评论

报告相同问题?

悬赏问题

  • ¥15 求解答一道线性规划题,用lingo编程运行,第一问要求写出数学模型和lingo语言编程模型,第二问第三问解答就行,我的ddl要到了谁来求了
  • ¥15 Ubuntu在安装序列比对软件STAR时出现报错如何解决
  • ¥50 树莓派安卓APK系统签名
  • ¥15 maple软件,用solve求反函数出现rootof,怎么办?
  • ¥65 汇编语言除法溢出问题
  • ¥15 Visual Studio问题
  • ¥20 求一个html代码,有偿
  • ¥100 关于使用MATLAB中copularnd函数的问题
  • ¥20 在虚拟机的pycharm上
  • ¥15 jupyterthemes 设置完毕后没有效果