i want to display question and answers with sequence(first:question then answers) how is it possible?
$servername = "localhost";
$username = "someone";
$password = "someonepassword";
$dbname = "quiz_app";
$pdo = new PDO("mysql:host=$servername;dbname=$dbname", $username, $password);
$statement = $pdo->prepare("SELECT * FROM question");
$statement2 = $pdo->prepare("SELECT a.id as answer_id, a.*,
q.id as question_id, q.*
FROM answer a
inner join question q on a.question_id = q.id");
$statement->execute();
$statement2->execute();
$result = $statement->fetchAll(PDO::FETCH_ASSOC);
$result2 = $statement2->fetchAll(PDO::FETCH_ASSOC);
$i=0;
foreach ($result as $row) {
$i++;
echo "<h5>".$i.'.'.$row['question_text']. "</h5>";
foreach ($result2 as $row2) {
echo "<input name='group". $row2['id'] ."' type='radio' id='". $row2['answer_id'] ."' />" . "<label for='". $row2['answer_id'] ."'>".$row2['answer_text']."</label>";
}
echo "<br>";
}
In this code questions and answers are ordered differently(all questions together and after them answers) how can i fix it?