SitePoint Sponsor

User Tag List

Results 1 to 7 of 7

Thread: limiting

  1. #1
    SitePoint Guru
    Join Date
    Apr 2001
    Location
    BC, Canada
    Posts
    630
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    limiting

    Hey all..

    $result =mysql_query("SELECT * FROM list WHERE buscat1='$category' OR buscat2='$category' OR buscat3='$category' ORDER BY name ASC",$db)
    or die("lINE 8");

    this gets everything in the database with the a particular catogry. And will display all hte results on one page... Now.. I need to make i grab them all...sort them alphabeticly by collum name.. then grab the first 20. that I can do kinda.. the problem lies in that I need to have a way to tell it to grab all the results with the approiate category, then sort them alphabeticly. Now... after the page with the intial 20, I need a link to the same page, but with the next 20 results.

    aby ideas?

  2. #2
    ********* Callithumpian silver trophy freakysid's Avatar
    Join Date
    Jun 2000
    Location
    Sydney, Australia
    Posts
    3,798
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    This might be of help
    http://www.sitepointforums.com/showt...threadid=16423
    Scroll down to my very last post in that thread.

  3. #3
    SitePoint Guru
    Join Date
    Apr 2001
    Location
    BC, Canada
    Posts
    630
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    $result =mysql_query("SELECT * FROM list WHERE buscat1='$category' OR buscat2='$category' OR buscat3='$category' ORDER BY name ASC LIMIT $offset, 20",$db);

    Im getting an error on this

    I dont have a value in offset..does that matter?

  4. #4
    SitePoint Guru
    Join Date
    Apr 2001
    Location
    BC, Canada
    Posts
    630
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I put a value in offset.. (0) and now there is no error, but I am getting all the results..not just 20

  5. #5
    ********* Callithumpian silver trophy freakysid's Avatar
    Join Date
    Jun 2000
    Location
    Sydney, Australia
    Posts
    3,798
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)


    That last sql you posted looks fine. And yes you would have to set $offset to hold a value.

  6. #6
    SitePoint Guru
    Join Date
    Apr 2001
    Location
    BC, Canada
    Posts
    630
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    so...

    LIMIT value1, value2

    value1 is where to start taking results... value2 is how many to take in?

  7. #7
    ********* Callithumpian silver trophy freakysid's Avatar
    Join Date
    Jun 2000
    Location
    Sydney, Australia
    Posts
    3,798
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Yes that's right. Also value1 is an optional agruement. For example:

    LIMIT 0, 20 <- limit to the first twenty records
    LIMIT 20, 20 <- skip the first twenty records and return the next twenty.

    LIMIT 20 <- no offset given, so just return the first twenty records.


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
  •