Noob在这里提醒。我只是(试图)自学PHP,因为我在实习工作中需要它。现在我正在创建一个调查,我正在尝试使用while
循环来向我的XAMPP显示问题及其各自的答案。我正在使用此代码:
<?php
mysqli_select_db($conn, "surveyordina");
//code hier schrijven
$sql = "SELECT questions_body FROM survey_questions where subthema_id = 1";
$sql2 = "SELECT answer_body FROM survey_answers where answer_id = 1 or answer_id = 2 or answer_id = 3";
$result = mysqli_query($conn, $sql);
$result2 = mysqli_query($conn, $sql2);
if(mysqli_num_rows($result2) > 0){
while($row = mysqli_fetch_assoc($result)) {
echo "<br>" ."Vraag: <br>" . $row["questions_body"]. "<br>";
while($row_answer = mysqli_fetch_assoc($result2)) {
echo $row_answer["answer_body"]. "<br>";
}
}
}
else{
echo "No results";
}
现在这段代码的返回部分如下所示:
Vraag: Is the organization aware of where all the personal data is stored? Be it on-site or in the cloud, hosted by the company or by a third party? Yes No I don't know Vraag: Is the organization able to locate and find personal data of a particular data subject? Vraag: Does the organization have technology in place to return all personal data on a given data subject, given a single search from personnel? Vraag: testerino kekkerino
我试图在每个问题下得到是,否和我不知道部分,但似乎只是在其中一个问题下得到它。
是否有方法可以在每个问题下返回整个答案部分?如果是这样,我是走在正确的道路上还是我做错了什么?
提前致谢。
答案 0 :(得分:0)
一旦你到达结果集的末尾,mysqli_fetch_assoc()
不仅仅是继续循环。所以你在第一个外部循环中遇到$result2
集的末尾,然后就是这样,没有更多的结果可以获取。
您应该获取$result2
循环之外的所有$result
结果,将结果分配给变量,然后在{{1}内循环 数组循环。
类似的东西:
$result