简体   繁体   中英

echo radiobutton value from mysql table

How can i loop all questions in a row to display as radio button answers?

I have 4 tables in $row that i want to print as radio button survey.

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

and so on.....

 <?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>";
 }
 ?>  

Replace this:

<?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>";
}
?>  

to this:

<?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>';
}
?>  

Use this

 $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>";

  }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM