Page 1 of 1

[help]Make pages for cms

Posted: Sat Oct 08, 2011 2:51 pm
by Securewebbase
Hi all

I'm working on a cms

lets assume that in index page we have 3 articles

I want to make page for the other article
for example article 4 to 6 be in page 2 , article 7 to 9 be in page 3 and ...

i want to pages be added when I add new articles

what should id do ?

Re: [help]Make pages for cms

Posted: Tue Oct 11, 2011 5:54 pm
by jraede
You can use the LIMIT clause in your MySQL query to paginate your results from the database. Ideally you would grab a query variable from the url for page and results_per_page, for example, and use that to generate the LIMIT clause. So http://www.your-site.com?page=2&results_per_page=10 would generate a LIMIT clause like so:

Code: Select all

...LIMIT 10, 10
To get that you would use

Code: Select all

<?php
$page = $_GET['page'];
$results = $_GET['results_per_page'];
$limit = 'LIMIT '.(($page - 1) * $results) . ', '.$results;
?>
Hope this helps.