Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    Regular Coder
    Join Date
    Jan 2008
    Posts
    334
    Thanks
    9
    Thanked 0 Times in 0 Posts

    limit a query on a page

    I know there is a way to do this in PHP because I see it done all of the time. What I'm trying to do is make a limit on each page that it will only display 10 lines of whatever that I'm calling from the database and then the user would have to click next to see more of the results that are coming from that query. How is this done, I can see how some of this may be done, but I can't totally see it...

    Could you give me a better idea how this is done?

    I would search on Google but I'm not to sure what to type in as a search term to find out how this is done.

    Thanks for the help.

    Jon W

  • #2
    Senior Coder
    Join Date
    May 2005
    Posts
    2,137
    Thanks
    96
    Thanked 72 Times in 72 Posts
    Well it depends on how you want to do it. If you want certain records, you could do this method.

    PHP Code:
    mysql_query("SELECT * FROM blah WHERE id>'49' AND id<'61'"); 
    Which will give you records 50 through 60. Or if you want the last records entered you could do this.

    PHP Code:
    mysql_query("SELECT * FROM blah ORDER BY id DESC LIMIT 10"); 

  • #3
    Regular Coder
    Join Date
    Jan 2008
    Posts
    334
    Thanks
    9
    Thanked 0 Times in 0 Posts
    Okay well, what I want is it to list them all. But say if I have 1000 records in my database.. I don't want all 1000 of them to come out on one page. So I want to setup a system so that it will list them 10 by 10. Not all 1000 at once.

    So say it will list 10 on one page and there would be links at the button looking something like:


    Page 1, 2, 3, 4, 5, 6, 7, 8, 9, 10

    And so on..

  • #4
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,979
    Thanks
    4
    Thanked 2,659 Times in 2,628 Posts
    This is called pagination.
    I've actually posted some pagination classes in the snippets directory, but the handling is rather complicated. Its also OO, so PHP5+ only. I also posted an edit to show how to handle the mysql LIMIT feature to trick the row seeking.
    You can probably google up some good tutorials if you search for PHP mysql pagination.
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 

  • #5
    Regular Coder
    Join Date
    Jan 2008
    Posts
    334
    Thanks
    9
    Thanked 0 Times in 0 Posts
    Okay, thanks a lot for your feedback.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •