Hi my code is not working properly. The second while loop is not working. I tried many times but I can't find the mistake. Is it anything wrong with the code? Thank you!
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>';
the loop below is not working
echo '<div>';
while ($stmt->fetch()) {echo $concurso.' • ';}
echo '</div>';
echo '</div>';
//<!--------calc-res------->
}
die();
}
Once you reach the end of the results in the first loop, there are no more rows to fetch. What you should do is put the values into an array during the first loop:
$concursos = array();
echo '<div>';
while ($stmt->fetch()) {
echo $date . '*';
$concursos[] = $concurso;
}
echo '</div>';
echo '<div>';
foreach ($concursos as $concurso) {
echo $concurso . '*';
}
echo '</div>';