I am trying now to get the value of every radio button to store in a database. The trick is I'm using while loop to display the question and the choices.
Here is my code in displaying the questions and choices.
class questions{
function __construct(){
$db= new dbConnect();
}
public function fetchRandom()
{
$qr=mysql_query("SELECT * FROM questionaires INNER JOIN choices ON questionaires.q_id=choices.q_id WHERE RAND()<(SELECT ((10/COUNT(*))*10) FROM questionaires) ORDER BY RAND() LIMIT 10");
$c=0;
echo "<table border='3' align='center' bordercolor='#CCCCCC'>
<tr>
<th>Number:</th>
<th>Question</th>
</tr>";
while($row=mysql_fetch_array($qr))
{
$c++;
echo "<tr>";
echo "<td>" . $c . "</td>";
echo "<td>";
echo $row['question'] . "<br>";
$ans_arr=array($row['choice_a'],$row['choice_b'],$row['choice_c'],$row['choice_d']);
shuffle($ans_arr);
echo "<input type='radio' name='ans".$c."' value='".$ans_arr[0]."'>".$ans_arr[0]."</input><br>";
echo "<input type='radio' name='ans".$c."' value='".$ans_arr[1]."'>".$ans_arr[1]."</input><br>";
echo "<input type='radio' name='ans".$c."' value='".$ans_arr[2]."'>".$ans_arr[2]."</input><br>";
echo "<input type='radio' name='ans".$c."' value='".$ans_arr[3]."'>".$ans_arr[3]."</input><br>";
echo "</td>";
echo "</tr>";
}
echo "</table>";
}
}
How can I store the answer of the user to database. Little help will be appreciated. Because I don't know how to code it from scratch. Thank you.
Aucun commentaire:
Enregistrer un commentaire