我在php中运行此代码,如果我尝试分别运行每个while循环,但是当我尝试执行嵌套whileloop时它会产生错误
List<List<Integer>> data = Arrays.asList(
Arrays.asList(1,2),
Arrays.asList(3,4,5),
Arrays.asList(6,7));
data.stream()
.flatMap(List::stream)
.peek(System.out::println)
.allMatch(x -> x < 4);
这是Php代码
Fatal error: Uncaught PDOException: SQLSTATE[IMSSP]: There are no more rows in the active result set. Since this result set is not scrollable, no more data may be retrieved. in C:\xampp\htdocs\survey-module\survey.php:13 Stack trace: #0 C:\xampp\htdocs\survey-module\survey.php(13): PDOStatement->fetch() #1 {main} thrown in
答案 0 :(得分:0)
显然MSSQL不允许在嵌套的同时进行多次抓取,所以我所做的是获取数据并将其放在关联数组中,这是代码。
$question_array = array();
while ($question = $questions->fetch()) {
$question_push = array('header'=>$question['header'],'question'=>$question['question']);
array_push($question_array,$question_push);
}
while ($question_validation =$header_questions->fetch()) {
foreach ($question_array as $key => $value) {
if($question_validation['header']==$value['header'])
{
echo $value['header'] ."-". $value['question'] ."<br>";
}
}
}
答案 1 :(得分:0)
您可以尝试获取数据并将其与null进行比较,因为我发现在获取最后一行时,下一行变为null,然后获取下一行将引发异常There are no more rows in the active result set
。
这很奇怪,不应该起作用-在尝试获取不存在的行时,我希望获得false
的值。
尽管如此-它可行,我不会抱怨;)
$survey_detail=$survey->viewSurvey('3');
$questions=$survey->indexQuestion('3');
while (($question_header = $header_questions->fetch()) !== null){
while (($question_detail = $questions->fetch()) !== null){
if($question_detail['header']==$question_header['header']){
echo $question_detail['header'] . "-".$question_detail['question']. "<br>";
}
}
}