来自mysql表的echo单选按钮值

时间:2014-08-06 12:39:22

标签: php

如何将所有问题连续循环显示为单选按钮答案?

我在$ row中有4个表格,我想打印成单选按钮调查。

Question nr1   (Radiobutton)Answer0   (Radiobutton)ansewer1   (Radiobutton)answer2
Question nr2   (Radiobutton)Answer0   (Radiobutton)ansewer1   (Radiobutton)answer2
Question nr3   (Radiobutton)Answer0   (Radiobutton)ansewer1   (Radiobutton)answer2

依旧.....

 <?php

 $result = mysqli_query($db,"SELECT * FROM que");

 while($row = mysqli_fetch_array($result)) {
  echo $row['que_id'] . " " . $row['que_question'] . " " . $row['que_answer0'] . " " . $row['que_answer1'] . " " . $row['que_answer2']  ;
 echo "<br>";
 }
 ?>  

2 个答案:

答案 0 :(得分:1)

替换它:

<?php

$result = mysqli_query($db,"SELECT * FROM que");

while($row = mysqli_fetch_array($result)) {
echo $row['que_id'] . " " . $row['que_question'] . " " . $row['que_answer0'] . " " . $row['que_answer1'] . " " . $row['que_answer2']  ;
echo "<br>";
}
?>  

到此:

<?php

$result = mysqli_query($db,"SELECT * FROM que");

while($row = mysqli_fetch_array($result)) {
   echo '' . $row['que_question'] . '<br>
<input type="radio" name="' . $row['que_id'] . '" value="male">' . $row['que_answer0'] . '<br>
<input type="radio" name="' . $row['que_id'] . '" value="male">' . $row['que_answer1'] . '<br>
<input type="radio" name="' . $row['que_id'] . '" value="male">' . $row['que_answer0'] . '<br>';
}
?>  

答案 1 :(得分:0)

使用此

 $result = mysqli_query($db,"SELECT * FROM que");

 while($row = mysqli_fetch_array($result)) 
{            

    echo $row['que_question'].' ';
    echo "<input type='radio' name='question[".$row['que_id']."]' value='".$row['que_answer1']."'">." ";
    echo "<input type='radio' name='question[".$row['que_id']."]' value='".$row['que_answer2']."'">." ";
    echo "<input type='radio' name='question[".$row['que_id']."]' value='".$row['que_answer3']."'">."<br>";

  }