[help]Make pages for cms

Not for 'how-to' coding questions but PHP theory instead, this forum is here for those of us who wish to learn about design aspects of programming with PHP.

Moderator: General Moderators

[help]Make pages for cms

Postby Securewebbase » Sat Oct 08, 2011 2:51 pm

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 ?
Securewebbase
Forum Newbie
 
Posts: 1
Joined: Mon Sep 19, 2011 4:59 pm

Re: [help]Make pages for cms

Postby jraede » Tue Oct 11, 2011 5:54 pm

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.
jraede
Forum Contributor
 
Posts: 254
Joined: Tue Feb 16, 2010 6:39 pm


Return to PHP - Theory and Design

Who is online

Users browsing this forum: No registered users and 1 guest