SitePoint Sponsor

User Tag List

Results 1 to 7 of 7
  1. #1
    SitePoint Enthusiast aaron888's Avatar
    Join Date
    Apr 2009
    Posts
    40
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    SELECT from table first 20 rows .. how ?

    Hi,

    My table has like 200 over rows.

    But I only wanna display the first 20 rows.
    Then at the bottom, I want to put a "NEXT" link, where if the user clicks next, it shows the next 20 rows and so on...

    Any idea how to do that ?
    I tried searching around.... but I am such a newbie... not really sure of good resources. lol

    Thanks all.

  2. #2
    SitePoint Addict joaquin_win's Avatar
    Join Date
    Jul 2005
    Location
    Venezuela
    Posts
    224
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Check Sitepoint's tut Perfect Pagination: http://www.sitepoint.com/article/per...hp-pagination/

  3. #3
    SQL Consultant gold trophysilver trophybronze trophy
    r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    39,336
    Mentioned
    63 Post(s)
    Tagged
    3 Thread(s)
    if you're using mysql, check out the LIMIT option of the SELECT statement

    make sure you have an ORDER BY clause, and then use:
    Code:
    LIMIT $rowstoskip, $rowstoprint
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"

  4. #4
    SitePoint Member
    Join Date
    Apr 2009
    Posts
    5
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    use LIMIT offset, Number

    For first 20, offset=0, Number=20

  5. #5
    John 8:24 JREAM's Avatar
    Join Date
    Sep 2007
    Location
    Florida
    Posts
    1,508
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    SELECT FROM place WHERE `id`='0' LIMIT 20
    Then next page:
    SELECT FROM place WHERE `id`='21' LIMIT 20

    cant you do that??

    nevermind if the IDs arent perfectly in a row itll get jumbled

  6. #6
    SitePoint Guru
    Join Date
    Jul 2005
    Location
    Orlando
    Posts
    634
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by JREAM View Post
    SELECT FROM place WHERE `id`='0' LIMIT 20
    Then next page:
    SELECT FROM place WHERE `id`='21' LIMIT 20

    cant you do that??

    nevermind if the IDs arent perfectly in a row itll get jumbled
    Assuming the id is the primary key, that'll just return one row.

  7. #7
    SitePoint Enthusiast aaron888's Avatar
    Join Date
    Apr 2009
    Posts
    40
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    ok, thanks everyone for all the tips.

    joaquin_win also shared some very good resource, and I am gonna be using that.


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
  •