I want to check if there are more than or equal to one rows in database with the field 'publish' = publish then show all posts (rows) where 'publish' = publish. For it I tried starting with an if statement - if row count is greater or equal to one than run while statement. But this restricts the while statement to display only 1 single post.
$query = "SELECT * FROM posts WHERE publish='publish' ORDER BY data_id DESC";
$result = mysqli_query($link, $query);
$row = mysqli_fetch_array($result);
$row_cnt = mysqli_num_rows($result);
if ($row_cnt >= 1) {
while($row = mysqli_fetch_array($result)){
echo '<h3>'. $row['title'] .'</h3>
<br><br>
<p>' . $row['post'] . '</p>;
}
} else {
echo '<h4>Sorry, no posts to display.</h4></div>';
}
Aucun commentaire:
Enregistrer un commentaire