Look into pagination.
It can actually seem pretty complex, but break it up into chunks and it should be possible to wrap your head around with some fiddling.
You need to:
1
Set a page size
2
Add a limit to your query
3
Since you now only fetch a subset of the table, you need to figure out the total number of items. You can…
a
Add SQL_CALC_FOUND_ROWS to the query and fetch the total rows
b
Run a separate query “SELECT count(*) FROM table” to get the row count, this is usually faster
[hr]
Something like this should get you started
[php]<?php
$pageSize = 5;
$page = isset($_GET[‘page’]) && (int) $_GET[‘page’] > 1 ? (int) $_GET[‘page’]-1 : 0;
// above we set the current page to a default (1) if get page is not set. If it is set we make sure it’s an valid integer. Note that as usual we start our index at 0 instead of 1. This just makes it easier when we add the limit to our query
$link = mysqli_connect("localhost","","","") or die("Error " . mysqli_error($link));
$result = mysqli_query($link, "SELECT count(*) FROM list LIMIT $page,$pageSize") or die("Error in the consult.." . mysqli_error($link));
$row = mysqli_fetch_array($result);
$accountsCount = $row[0];
$totalPages = $accountsCount / $pageSize;
$result = mysqli_query($link, "SELECT * FROM list") or die("Error in the consult.." . mysqli_error($link));
$accounts = array();
while($row = mysqli_fetch_array($result)) {
$accounts[] = $row;
} [/php]
[hr]
With the above you should be able to use ?page=x to change page. Usually you would want a pagination menu after the entries.
[php]
<?php for ($i = 1; $i <= $totalPages; $i++) { ?>
-
<?= $i ?>
<?php } ?>
[/php]
If we have 50 accounts and a pageSize of 5 we will get 10 links printed. Links should be styled appropriatly.