Results 1 to 3 of 3
Thread: Forum database
Jun 4, 2011, 12:25 #1
- Join Date
- Mar 2003
- 0 Post(s)
- 0 Thread(s)
I am still learning the basics with databases
I am making a database for a forum. I am trying to select the list of threads ... page one... page two etc with just lists of thread titles... all listed according to date time.
How would I code the select where I wanted to selct for page two... with twenty posts per page so that would be between 21 and 40 (with 21 being the 21st most recent post)
ALSO when I create a table with a primary index do I have to set the index when I select
Jun 4, 2011, 16:47 #2
What you're trying to do is called Pagination. Please search "PHP Pagination" on Google, for a gazillion tutorials.
To make a select starting from a particular key, you should use an OFFSET.
Getting all data:
SELECT * FROM thread_list;
Getting only the first ten:
SELECT * FROM thread_list LIMIT 10;
Now, get the index of the last item using PHP. Increment it by 1. Then:
SELECT * FROM thread_list LIMIT 10 OFFSET last_incremented_id;
Not sure if I understood your second question...
Jun 4, 2011, 23:19 #3
- Join Date
- Jul 2002
- Toronto, Canada
- 63 Post(s)
- 3 Thread(s)
also, LIMIT makes very little sense without ORDER BY
so the first query, to get the first 20 rows, would be ...Code:
SELECT columns FROM thread_list ORDER BY postdate DESC LIMIT 0,20Code:
SELECT columns FROM thread_list ORDER BY postdate DESC LIMIT 20,20Code:
SELECT columns FROM thread_list ORDER BY postdate DESC LIMIT 40,20