Is it possible to collect two queries in one while loop?
I have tried the code below, but do not get the expected result.
<?php
include 'conn.php';
$query_answers=mysqli_query($conn,"SELECT * FROM answers");
while($row_answers=mysqli_fetch_array($query_answers)){
?>
<table>
<tr>
<td><input type="text" name="" value="<?php echo $row_answers['answer_text'];?>"></td>
<td><select>
<option>
<?php
$query_question = mysqli_query($conn, "SELECT * FROM questions WHERE question_id= ".$row_answers['next_question_id']."");
while($row_answers=mysqli_fetch_array($query_question)){
echo $query_question['question_text'];
}
?>
</option>
</select></td>
</tr>
</table>
<?php
}
?>
joins. The issue you have though is you are using the same variable name so the result set is overwritten.$row_answersin both loops. I think your inner loop should use$row_questionsor something like that instead. And as mentioned above, you could write this in a single query if you would prefer and handle the logic accordingly within the code.