I'm rather new to PHP and coding, I have my index.php
displaying the last 20 blog posts submitted into my database. How would I create pagination so that it would only display 10 posts at a time, with a next a previous button to view another 10 posts?
<ol>
<?php
$link = mysqli_connect( 'localhost', 'BlogDB', 'password' );
mysqli_select_db( $link, 'BlogDB' );
$results = mysqli_query( $link, 'SELECT * FROM Blog ' );
$resultsArr = array();
while( $record = mysqli_fetch_assoc( $results ) ) {
$title = $record['title'];
$email = $record['email'];
$post = $record['post'];
array_push( $resultsArr, "<li>$title <br> $email <br>$post</li>");
}
mysqli_free_result( $results );
for ($i = count($resultsArr); $i > 0; $i--) {
if ($i >= count($resultsArr) - 10) {
print $resultsArr[$i];
}
}
?>
</ol>