和相同或另一页中的Submited Radio Buttons值?

时间:2012-09-03 10:53:29

标签: php

我是PHP新手,我正在研究调查和数据库。我有两个表:一个包含问题,另一个包含答案。这两个表具有以下属性:

     _________________           _________________
    | TABLE-QUESTION  |         | TABLE-ANSWER    |
    |_________________|         |_________________|
    |  id             |         |  id             |
    |  survey_name    |         |  qid            |
    |  question       |         |  answer         |
    |  status         |         |  answer_value   |
    |_________________|         |_________________|

每个答案都有多个值,并使用单选按钮

进行选择
 <?php
      $newsurvey=$db->get_results("SELECT * FROM question where status='1' order by `id` ");
      if($newsurvey)
      {
           foreach($newsurvey as $survey1)
           {
 ?>         
                <h3><?php echo $survey1->question?></h3>

                <?php
                     $slider=$db->get_results("SELECT * FROM answer where qid='$survey1->id' ");
                     if($slider)
                     {
                          foreach($slider as $answer1)
                          {
                ?>
                               <div class="entry">
                                    <input type="radio" name='$survey1->id' value="
                                         <?php echo $answer1->answer_value?>"/>
                                    <?php echo $answer1->answer?>
                                </div>
                     <?php
                          }
                     }
                     ?>
            <?php
                 }
           }
           ?>

           <input type="Submit" value="Submit">

我想要的是将所有提交的单选按钮值相加并存储在另一个页面中。

怎么做?

2 个答案:

答案 0 :(得分:0)

您可以使用多个电台e.q。

<input type="radio" name="survey[SURVEY_ID]">

尝试在$ _SESSION中存储e.q。

$_SESSION["survey"] = $_POST["survey"]; // Under key 'survey' you have array of radio buttons

答案 1 :(得分:0)

试试这个<input type="radio" name='answer_value[]' value="<?php echo $answer1->answer_value?>"/><?php echo $answer1->answer?>

如果您打印$_POST['answer_value'],您将获得数组中的所有选择值,使用$sum = array_sum($_POST['answer_value'])对所有选定值求和...