I'm building my own CMS. I have an administration system made and I can insert posts in the database with it, showing posts isn't a problem, but I have no idea on how to do the pagination.
And this is my query:
SELECT * FROM `posts` WHERE `status` != 'draft'
Build your query to have a
LIMIT
End SQL Result;
For example;
Have a read of
LIMIT
You will need to
ORDER BY
your primary key, as it's not "safe" to rely on the order MySQL gives without theORDER BY
clause, in terms of pagination (as you may get duplicate rows (on different pages))To paginate with PHP
Something like this should suffice
As suggested in the comments it's good practice to use prepare statements, by binding parameters