I need to run a SQL query with a where and a limit clause I seem to be having an issue with running when I include the where clause
Warning: mysqli_fetch_array() expects parameter 1 to be mysqli_result, bool given in C:\xampp\htdocs\Aerosa\functions\get_posts.php on line 30
the limit query runs as expected until I had a where clause
<?php
$status = 'publish';
// define how many results you want per page
$results_per_page = 2;
// find out the number of results stored in database
$sql = "SELECT * FROM at_posts ";
$result = mysqli_query($conn, $sql);
$number_of_results = mysqli_num_rows($result);
// determine number of total pages available
$number_of_pages = ceil($number_of_results/$results_per_page);
// determine which page number visitor is currently on
if (!isset($_GET['page'])) {
$page = 1;
} else {
$page = $_GET['page'];
}
// determine the sql LIMIT starting number for the results on the displaying page
$this_page_first_result = ($page-1)*$results_per_page;
// retrieve selected results from database and display them on page
$sql='SELECT * FROM at_posts WHERE post_status = '.$status.' LIMIT ' . $this_page_first_result . ',' . $results_per_page;
$result = mysqli_query($conn, $sql);
while($row = mysqli_fetch_array($result)) {
echo $row['id'] . ' ' . $row['post_name']. '<br>';
}
echo '<nav aria-label="Page navigation">
<ul class="pagination">';
// display the links to the pages
for ($page=1;$page<=$number_of_pages;$page++) {
echo '<li class="page-item"><a class="page-link" href="?page=' . $page . '">' . $page . '</a></li>';
}
echo ' </ul>
</nav>';
?>
Thanks beforehand.