是否可以在一个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
}
?>
1条答案
按热度按时间tyky79it1#
您正在覆盖
row_answers
变量,而不是对问题的查询使用其他变量。此外,您在循环中引用的是查询而不是其结果: