So, i have this database right, with some fields called ‘id’, ‘title’ and ‘message’. Now i got like 700 messages in the database. So all i wanna do, is set a limit of max 50 message title’s per page, and make multiple pages… How can i do that?
I only know to get the first page, using LIMIT…
As you guessed, you have to use the
LIMITkeyword.It accepts two value (quoting) :
In your case, you’ll have to use something like this for the first page :
And, then, for the second page :
And for the third one :
And so on 😉
Edit after the comment : to get the page number, you’ll have to receive it from your URLs, that would look like this :
Then, you’ll calculate the first value for the limit, :
And inject it in your query :
Constructing URLs to the differents pages is now a matter of getting URLs such as these :
If you know you have 700 elements, and 50 per page, you’ll have 700/50 pages 😉
So, something like this should do the trick :
Of course, 700 is a value that can probably change, and should not be hard-coded : it should be determined from the database, using a
countquery :