SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Enthusiast
    Join Date
    Nov 2005
    Posts
    92
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Pagination system, 1 or 2 query?

    Hi

    i want to know if for a pagination system, i use the mysql_num_rows on a query to get the total, and then query again to limit the # of results to display is an effective way of doing it since you have 2 query on a table that can be large.

    Would it be efficient to use only one query that get all rows and then simply limit what is displayed with PHP instead in your while loop?

    This way you have only one query.

    What do you think?

    Thanks

  2. #2
    SQL Consultant gold trophysilver trophybronze trophy
    r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    39,350
    Mentioned
    63 Post(s)
    Tagged
    3 Thread(s)
    use 1 query, not 2

    look up the FOUND_ROWS function

    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"

  3. #3
    SitePoint Enthusiast
    Join Date
    Nov 2005
    Posts
    92
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Perfect Thanks.

    I use the SQL_CALC_FOUND_ROWS in my query and then query again with only the FOUND_ROWS() after which is supposed to be a lot faster than doing the same query twice.

    Working great thanks.

    For reference


Bookmarks

Posting Permissions

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