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 9116813
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T04:45:47+00:00 2026-06-17T04:45:47+00:00

I have been trying to resolve a paging problem and I do not understand

  • 0

I have been trying to resolve a paging problem and I do not understand the following code.

                $lstart = ($page * 6) -6;
                $lend = ($page * 6)-1;
                $limit = $lstart.','.$lend;

The results I get are mixed. I should get six articles per page, but it is inconsistent. The code is incorporated in a script I inherited from someone else and I am trying to fix it. Can someone explain this code to me? In the query, LIMIT=$limit.

  • 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-06-17T04:45:48+00:00Added an answer on June 17, 2026 at 4:45 am

    It should be…

    $lstart = ($page * 6) -6; // quite frankly, it's clearer to write...
           // ($page - 1) * 6
    $limit = $lstart.',6';
    

    The second clause in limit declares how many items. Not up to a certain point.


    From mysql docs: (copy/paste)

    SELECT * FROM tbl LIMIT 5,10;  # Retrieve rows 6-15
    

    So, 1,10 would be rows 2-11
    Thus, to get row 1, you need to set the offset to zero: 0,10 which would give you rows 1-10.

    You can also check out further tutorials on LIMIT here: http://php.about.com/od/mysqlcommands/g/Limit_sql.htm


    Code with explanation.

    $rows_per_page = 6; // you're trying to get 6 rows for every "page".
    
    // On page 1, you'd want rows 0-5 (6 rows inclusively)
    // On page 2, you'd want rows 6-111 (again, 6 rows inclusively)
    // and so forth.
    // So when $page == 1, you want to start at 0, on page 2, start at 6....
    // To express this pattern mathematically, we write:
    $start = ($page - 1) * 6
    
    // mysql takes offset and number as it's two variables in the LIMIT clause, 
    // in that order, when two are provided.
    // So we write:
    $query = "SELECT * FROM table WHERE 1 LIMIT $start, $rows_per_page;";
    
    // So, at page 1, you get
    $query = "SELECT * FROM table WHERE 1 LIMIT 0, 6;"; // if we were to substitute the variables.
    $query = "SELECT * FROM table WHERE 1 LIMIT 6, 6;"; // at page 2
    $query = "SELECT * FROM table WHERE 1 LIMIT 12, 6;"; // at page 3
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have been trying to resolve this but just couldn't get it right. I
I have been trying to run the sample code available at http://samples.google-api-java-client.googlecode.com/hg/tasks-android-sample/instructions.html I have
I have been trying to figure out the best practices to write test-friendly code,
Been trying to resolve this problem with a rewrite rule that assigns a subdomain
I have been trying to get this problem resolved for week and have get
I've been trying to resolve this issue since morning. I have client and server
I have been trying to set up spree and refinery together with the following
i have been trying the code using mutex but im unable to open my
I have issues with my code and have been tearing my hair apart trying
I've been trying to resolve this problem on my own and for the life

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.