like the next 15 values in the ITEMS table sorted by date added? enter code here
views:
33answers:
3
+2
A:
SELECT column FROM table
LIMIT 10 OFFSET 10
http://www.petefreitag.com/item/451.cfm mentions OFFSET
is supported by both PostgreSQL and MySQL.
sarnold
2010-08-03 23:41:30
+1
A:
It looks like you need to look at the LIMIT
clause:
SELECT *
FROM items
ORDER BY date_added DESC
LIMIT 0, 15;
Then to display the next 15 items, simply change the 0
of the LIMIT
clause to 15
... then to 30
... then to 45
... and so on. This is called pagination.
Daniel Vassallo
2010-08-03 23:42:24
makes sense in theory- but what would I use to actually allow users to keep changing that "starting point" woudl i build a new link that said "more" and change the code behind that... (does that make sense)
adam
2010-08-03 23:54:12
@adam: Yes, that's one way to tackle it. You simply need to keep track of what page the user is looking at, and if the user is in page 4, you should simply change the `LIMIT` to `60, 15`, to display the 15 rows from row `60` to row `74`. Otherwise, you may prefer to alter the last parameter of the `LIMIT` clause, such that you always return the full result set from the first row, to the row number you specify. For example `LIMIT 0, 45` will display the first 45 rows... `LIMIT 0, 60` the first 60 rows... and so on.
Daniel Vassallo
2010-08-04 00:00:05
+2
A:
Before, you query
SELECT COUNT(foo) AS number_of_elements FROM table;
in order to know how many pages ( CEIL(number_of_elements / elements_per_page)
) you need.
nononever
2010-08-03 23:47:12