Pagination system error

3 replies
I'm trying to create a pagination system, but there is a problem. I created this page by following a youtube tutorial. The page shown in tutorial works well, but when I write the code for my page, it give me an error.

Here is the code.
$perPage = 5;
if (!isset($_GET['submit'])) {
	header("location: index.php?page=1");
else {
	$page = $_GET['submit']; }

	$start = (($page - 1) * $perPage);
	$con = mysqli_connect("", "a8995753_db2", "xxxxxxxxx", "a8995753_db2") or die("Error ee oay: " . mysqli_connect_error());
$query = "SELECT * FROM customer";
$numOfRows = mysqli_num_rows(mysqli_query($con, $query));
$numOfPages = ceil($numOfRows / $perPage);
$query .= " LIMIT $start, $perPage";
$exQuery = mysqli_query($con, $query);
while ($row = mysqli_fetch_array($exQuery)) {
	 echo $row['custID'] . " " . $row['name'] . "<br>";
And here is the URL to my test website where you can see the error. The website doesn't work.
Please help me to solve this problem.
#error #pagination #system
  • Profile picture of the author Brian Tayler
    Line 4, change index.php?page=1 to index.php?submit=1

    Right now submit is never set for $_GET so you're stuck in a loop.
    {{ DiscussionBoard.errors[8190069].message }}
  • Profile picture of the author Valdor Kiebach
    Indeed, at the moment the only bit of code being processed is:

    if (!isset($_GET['submit'])) { header("location: index.php?page=1"); }

    This is because this line of code is saying ' if the value of submit is not set then redirect to location: index.php?page=1' which still does not set the value for submit so it is an infinate loop.
    This line needs to be:
    if (!isset($_GET['submit'])) { header("location: index.php?submit=1"); }

    You can see the working page by using the correct url:
    {{ DiscussionBoard.errors[8190137].message }}
  • Profile picture of the author crescendo
    Yes am also agree with you.It should be like this:
    if (!isset($_GET['submit'])) {
    header("location: index.php?submit=1");
    {{ DiscussionBoard.errors[8199668].message }}

Trending Topics