SitePoint Sponsor |
|
User Tag List
Results 1 to 7 of 7
Thread: limiting
-
May 25, 2001, 16:41 #1
- 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?
-
May 25, 2001, 17:51 #2
- 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.
-
May 25, 2001, 17:59 #3
- 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?
-
May 25, 2001, 18:01 #4
- 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
-
May 25, 2001, 18:24 #5
- 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.
-
May 25, 2001, 18:31 #6
- 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?
-
May 25, 2001, 18:40 #7
- 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