$stmt = $conn->prepare($sql);
$stmt->execute($array);
$rows = $stmt->rowCount();
if($rows >= 1) {
$x = $stmt->fetch();
echo '<div>'.$x['heading'].'</div>';
while($row = $stmt->fetch()) {
echo '<div>'.$row['article'].'</div>';
}
} else {
echo 'Nothing found';
}
When doing like above, can you see why the loop outputs only one row when there are several? It happens when I use fetch twice.
Also, how can I avoid having to use fetch twice in there? It's fetched once, can i use that same fetched data again?