开发者

value getting array in php

开发者 https://www.devze.com 2023-01-27 05:23 出处:网络
I am doing a online test I fetch question and option from database.... I need to select which option they choosed and que开发者_Go百科stion id....to the next page for the answered question or not.....

I am doing a online test I fetch question and option from database.... I need to select which option they choosed and que开发者_Go百科stion id....to the next page for the answered question or not.....I got only they selected option I need get all value....

my php code as follows

 <tr>
    <td height="30"><?= $id?></td>
    <td height="30" colspan="2"><?= $question ?></td>
  </tr>

   <?php 
      if($option1!='') { ?>

  <tr>
    <td height="30"><input type="radio" name="answer[<? echo $id?>]"  value="<?php echo $id?>-<?php echo $option1?>" /></td>
    <td height="30" colspan="2"><?= $option1?></td>
  </tr>
  <?php }?>
  <?php if($option2!='') {?>
  <tr>
    <td height="30"><input type="radio" name="answer[<? echo $id?>]"    value="<?php echo $id?>-<?php echo $option2?>" /></td>
    <td height="30" colspan="2"><?= $option2?></td>
  </tr><?php }?>
  <?php if($option3!='') {?>
  <tr>
    <td height="30"><input type="radio" name="answer[<? echo $id?>]"    value="<?php echo $id?>-<?php echo $option3?>"  /></td>
    <td height="30" colspan="2"><?= $option3?></td>
  </tr><?php }?>
   <?php if($option4!='') {?>
  <tr>
    <td height="30"><input type="radio" name="answer[<? echo $id?>]"    value="<?php echo $id?>-<?php echo $option4?>"  /></td>
    <td height="30" colspan="2" ><?= $option4?></td>
  </tr>

 <?  }


$id will have the same value for all your options.

So you might want to put name="answer" instead:

<input type="radio" name="answer" value="<?php echo $id?>-<?php echo $option2?>" />

On your result page $_GET['answer'] should then have the correct value.


You could send all the answers as hidden elements:

<input type="hidden" name="allanswers[]" value="Answer 1" />
<input type="hidden" name="allanswers[]" value="Answer 2" />
<input type="hidden" name="allanswers[]" value="Answer 3" />
<input type="hidden" name="allanswers[]" value="Answer 4" />
0

精彩评论

暂无评论...
验证码 换一张
取 消