您好我的代码无法正常工作。第二个while循环不起作用。我尝试了很多次,但我找不到错误。代码有什么问题吗?谢谢!
if ($stmt = $post_con->prepare('SELECT id, data FROM tb WHERE CONCAT(" ", res, " ") LIKE CONCAT("% ", ?, " %")')) {
/* bind parameters for markers */
$stmt->bind_param("s", $d1);
/* execute query */
$stmt->execute();
/* get num of rows */
$stmt->store_result();
$qde = $stmt->num_rows;
/* bind result variables */
$stmt->bind_result($concurso, $date);
echo '<div>';
while ($stmt->fetch()) {echo $date.' • ';}
echo '</div>';
以下循环无效
echo '<div>';
while ($stmt->fetch()) {echo $concurso.' • ';}
echo '</div>';
echo '</div>';
//<!--------calc-res------->
}
die();
}
答案 0 :(得分:0)
在第一个循环中到达结果的末尾后,就不再有要获取的行了。您应该做的是在第一个循环期间将值放入数组中:
$concursos = array();
echo '<div>';
while ($stmt->fetch()) {
echo $date . '*';
$concursos[] = $concurso;
}
echo '</div>';
echo '<div>';
foreach ($concursos as $concurso) {
echo $concurso . '*';
}
echo '</div>';