Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 122071
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T04:04:15+00:00 2026-05-11T04:04:15+00:00

I have the following code, which is the basis for pagination in a larger

  • 0

I have the following code, which is the basis for pagination in a larger application. However, it does not work, as although I should be obtaining the value of pg from the url, pg never goes higher than 2. For some reason, next = pg+1; seems to always see pg as 1, regardless of what is passed on the url. It is a similar problem with last. I assume I am overriding the value obtained from GET, but I am unsure where.

The problem seems to be in how I am working out $max and the limit, as instead of 0, 10, -10, 10 gets passed. Also the ifcode before $max does not seem to succeed in stopping pg from being 0.

<?php if (isset($_GET['pg'])) {     $pg = $_GET['pg']; } else $pg = 1; $con = mysql_connect('localhost','',''); if(!$con) {     die('Connection failed because of' .mysql_error()); } mysql_select_db('ebay',$con);  if ($pg < 1) {     $pg = 1; } elseif ($pg > $last) {     $pg = $last; } $table = 'AUCTIONS'; $page_rows = 10; $max = ' limit ' .($pg - 1) * $page_rows .', ' .$page_rows; $rows = getRowsByArticleSearch($query, $table, $max); $rowcount = count($rows); echo $rowcount; $last = ceil($rowcount/$page_rows); $page_rows = 10; $rowcount = 2; // Would normally obtain the number of rows returned, but database stuff is snipped for brevity $last = ceil($rowcount/$page_rows); if ($pg < 1) {     $pg = 1; } elseif ($pg > $last) {     $pg = $last; } $self = htmlspecialchars($_SERVER['PHP_SELF'],ENT_QUOTES,'utf-8'); echo ' <a href='$self?pg=1'> <<-First</a> '; $previous = $pg-1; echo ' <a href='$self?pg=$previous'> <-Previous</a> '; echo '---------------------------'; $next = $pg+1; echo ' <a href='$self?pg=$next'>Next -></a> '; echo ' <a href='$self?pg=$last'>Last ->></a> '; 
  • 1 1 Answer
  • 1 View
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-11T04:04:15+00:00Added an answer on May 11, 2026 at 4:04 am

    based on the now revised question:

    $rowcount = count($rows); 

    will naturally always return 10, as you’re limiting the result

    ... LIMIT 10; 

    But this might help:

    SQL CALC FOUND ROWS Example:

    mysql> SELECT SQL_CALC_FOUND_ROWS * FROM tbl_name     -> WHERE id > 100 LIMIT 10; mysql> SELECT FOUND_ROWS(); 

    The first query will still return your articles, while the second will return the number of rows the previous select would have had if not using the LIMIT clause.

    Hope that helps.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following code, which works fine , however when I change the
Hello I have the following bit of code which seems to work, but I'm
I have following code which works for radio buttons but need to be changed
I want to know is below code correct ? I have following code which
I have the following code which definitely returns a proper data result if I
I have the following code which is working, I was wondering if this can
I have the following code which is used to upload large files (~6MB) to
i have the following code which switches some fullscreen-background-images (fadeOut, fadeIn). setInterval(function() { var
I have the following code which is fine if I give invalid parameters (though,
I have the following code which will generate two pdf files containing plots to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.