You need to adjust your logic a small bit. The total number of pages should be changed. It is currently:
$pages = mysqli_num_rows($pages_query) / $per_page;
But, needs to be:
$pages = ceiling(mysqli_num_rows($pages_query) / $per_page);
This is to count the left overs from the division as a page. Also, some other minor changes…
First, change this as we discussed before…
if (!isset($_GET['pages']))
{
echo "<meta http-equiv='refresh' content='0;url=view.php?page=1'>";
}
else
{
$pages = $_GET['pages'];
}
$start = (($pages - 1)*$per_page);
To something like this…
$start = 1;
if (isset($_GET['pages']))
$start = $_GET['pages'];
}
Much less complicated. You don’t need to refresh anything! The starting page is either 1 or the one sent to the page from the pagination buttons.
Next, the second query that pulls just one page of data is using a starting page number not the record number to start at. This needs to be altered slightly. The old one is:
$result = mysqli_query($link,"SELECT * FROM orders WHERE OrderBy = '$username' AND Status = 'Layon' LIMIT $start,$per_page");
New version:
$result = mysqli_query($link,"SELECT * FROM orders WHERE OrderBy = '$username' AND Status = 'Layon' LIMIT ($start-1)*$per_page, $per_page");
This uses the page number 1,2,3, etc times the number per page. So, 1 would be record 0, 2 is record 3, etc.
Try these minor changes and let us know.