Results 1 to 7 of 7

Thread: Limiting number of records to display

  1. #1

    Thread Starter
    PowerPoster cafeenman's Avatar
    Join Date
    Mar 2002
    Location
    Florida
    Posts
    2,819

    Limiting number of records to display

    My mySQL database table has around 200+ tables and it's doing this weird flashy thing as the page is being generated. I don't know if that's because my code is terrible or if it's just too many records to display on one page.

    How can I limit the number of records to, say, 25 per page and have back and next buttons generated?

  2. #2
    Stuck in the 80s The Hobo's Avatar
    Join Date
    Jul 2001
    Location
    Michigan
    Posts
    7,256
    Use "LIMIT" in your SQL query. "SELECT * From table LIMIT 5, 50" Which means (unless I have the 5 and 50 backwards) "Show only 5 records starting at 50."
    My evil laugh has a squeak in it.

    kristopherwilson.com

  3. #3

    Thread Starter
    PowerPoster cafeenman's Avatar
    Join Date
    Mar 2002
    Location
    Florida
    Posts
    2,819
    will that automatically display next and back buttons or just display 5 records and I have to figure out the rest?

  4. #4
    Stuck in the 80s The Hobo's Avatar
    Join Date
    Jul 2001
    Location
    Michigan
    Posts
    7,256
    You're going to have to figure it out, but it's not that hard.

    Number of pages needed = ceil(mysql_num_rows() / 5)
    Then just keep track of the current page and the starting number.
    My evil laugh has a squeak in it.

    kristopherwilson.com

  5. #5
    Stuck in the 80s The Hobo's Avatar
    Join Date
    Jul 2001
    Location
    Michigan
    Posts
    7,256
    You're going to have to do it yourself, but it's not that hard.

    Just keep track of the current page. You can get the total number of needed page by doing:

    PHP Code:
    ceil(mysql_num_rows($something)) / 5
    I'm sure there's examples of it somewhere.
    My evil laugh has a squeak in it.

    kristopherwilson.com

  6. #6
    scoutt
    Guest
    Originally posted by The Hobo
    Use "LIMIT" in your SQL query. "SELECT * From table LIMIT 5, 50" Which means (unless I have the 5 and 50 backwards) "Show only 5 records starting at 50."
    heh you have it backwards.

    select * from table LIMIT 5,10; # Retrieve rows 6-15
    LIMIT (offset,) (rows)

  7. #7
    Stuck in the 80s The Hobo's Avatar
    Join Date
    Jul 2001
    Location
    Michigan
    Posts
    7,256
    bah, I figured as much
    My evil laugh has a squeak in it.

    kristopherwilson.com

Posting Permissions

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



Click Here to Expand Forum to Full Width