是否可以在一个while循环中收集两个查询?
我已经尝试过以下代码,但没有得到预期的结果。
<?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
}
?>
答案 0 :(得分:1)
您正在覆盖row_answers
变量,而不是使用不同的变量来查询问题。此外,您正在引用查询而不是循环中的结果:
while ($row_questions = mysqli_fetch_array($query_question)) {
echo $row_questions['question_text'];
}