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

  • SEARCH
  • Home
  • 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 6606347
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T19:23:10+00:00 2026-05-25T19:23:10+00:00

Have a simple page that pulls results from MySQL and displays them in a

  • 0

Have a simple page that pulls results from MySQL and displays them in a table. I have enabled paging on the results, and allowed the user to set the number of results being displayed per page. I am passing two querystring values to handle this: ‘page’ and ‘count’.

I am then taking these values to calculate the LIMIT’s of my MySQL query, using the SQL_CALC_FOUND_ROWS directive and following that with a call to SELECT FOUND_ROWS(); to get the total number of results. This all works nicely.

Now, I want to validate the querystring values. As I am storing the possible “correct” values for the results/page value of ‘count’ in an array, I simply check that the passed ‘count’ value is in that array, and if not set it to the default value. For the ‘page’ value, I am having a bit of a mental block… in order to determine if there are any results for the passed ‘page’, meaning it is “correct”, I need to go to the database and find the result count first, but since I only want to go to the db once, I need to include the LIMIT’s, which are based on the passed ‘page’ value… chicken and egg. I have a couple thoughts on how to solve this:

  1. Run the query as coded above, and if the ((‘page’ – 1) * ‘count’) result is greater than the value returned from SELECT FOUND_ROWS();, re-run the query with new LIMIT’s set to 0, count.

  2. Get the full result set, verify that the passed page is correct, then do another pull from the database with the LIMIT values.

I’d rather not go back to the database at all, but as I mentioned, having a mental block on this rather common issue.

Thanks,

Paul

  • 1 1 Answer
  • 0 Views
  • 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. Editorial Team
    Editorial Team
    2026-05-25T19:23:11+00:00Added an answer on May 25, 2026 at 7:23 pm

    I ended up using the first solution above –

    1. Run the query as coded above, and if the ((‘page’ – 1) * ‘count’) result is greater than the value returned from SELECT FOUND_ROWS();, re-run the query with new LIMIT’s set to 0, count.

    It’s not perfect in that a second database pull is required for cases where the passed page value is bad, but given that is an unexpected case only triggered by the intentional passage of bad data on the part of the user, it’s acceptable. If anyone else has a better solution, I’d be happy to re-open the question.

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

Sidebar

Related Questions

I have a simple php page that displays data from a mysql database. I
I have a simple cart page that displays items that are in someones cart,
I have a log in page that pulls information from a data base, I
I have a simple erb template that pulls information from a (Grit) git repository.
I have a simple web page that till now didn't need any login. It
I have a simple django page that has a counter on it. I use
I am simply learing Ajax with jQuery and have a simple page method that
I have a very simple ASP.Net page that acts as a front end for
I have a simple jQuery code that runs on a web page that has
I have a simple iPhone application that is very similar to the Page Control

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.