I have a really large data set from SQL that i need to paginate.
I have an issue with my pagination code. The code does show the page number in the URL and it does give me pagination hyperlinks at the bottom of the table. However, any page I click on, it outputs the same exact portion of the sql datatable.
Also, I'm doing this in wordpress.
// define how many results you want per page
$results_per_page = 10;
// find out the number of results stored in database
$sql='SELECT * FROM ETF';
$result = mysqli_query($con, $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 ETF LIMIT ' . $this_page_first_result . "," .$results_per_page;
$result = mysqli_query($con, $sql);
while($row = mysqli_fetch_array($result)) {
echo $row['ETF'] . ' ' . $row['ETF NAME']. '<br>';
}
// display the links to the pages
for ($page=1;$page<=$number_of_pages;$page++) {
echo '<a href="index.php/stocks/sec-forms/?page=' . $page . '">' . $page. '</a>';
}