SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Zealot JordanTLClive's Avatar
    Join Date
    Feb 2001
    Location
    Las Vegas, NV
    Posts
    118
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Getting a certain number of rows

    I want to be able to select rows 1 through 11, and then 12 through 22, etc through my script but I'm having trouble. I used LIMIT 1, 11 yet it doesnt always retrieve data when it should. Could someone please explain to me how to retrieve rows between x and y?
    -Jordan

  2. #2
    SitePoint Wizard johnn's Avatar
    Join Date
    Mar 2001
    Location
    Southern California, USA
    Posts
    1,181
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi Jordan,
    I think row 1 begins with 0, so it should be row 0.

    $offset = 0;
    SELECT * FROM tablename ORDER BY fieldname
    LIMIT $offset, 11
    //the above statement will select the first 11 rows
    $offset += 11;

    SELECT * FROM tablename ORDER BY fieldname
    LIMIT $offset, 11
    //the above statement should select the next 11 rows from
    //row 11th thru 22


    John


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
  •