divide into pages (solved)

Codes here !

Moderators: egami, macek, gesf

Post Reply
unisabilly
New php-forum User
New php-forum User
Posts: 19
Joined: Wed Aug 17, 2005 6:00 am

Wed May 03, 2006 11:05 am

for every forum, if the posts exceed certain amount, it will divide into several pages.
the question is how can I do that !?
for example the first page of the forum i can just use " select content from post order by time limit 10 "
I think this will do the first page, but with the second page how can i make it to get the next 10 posts ( from 11 - 20 )..!?
THANX ~
Last edited by unisabilly on Fri May 05, 2006 2:22 pm, edited 1 time in total.

Coditor
New php-forum User
New php-forum User
Posts: 243
Joined: Wed Feb 01, 2006 9:18 am
Location: Netherlands
Contact:

Wed May 03, 2006 11:19 pm

Provide the page in a parameter, by making links like this:

<a href="posting.php?page=2">previous</a>
<a href="posting.php?page=4">next</a>

(in this example the current page would be 3)

In posting.php:

Code: Select all

<?php
$page = 1;
if (isset($_GET['page']) && is_numeric($_GET['page'])) {
   $page = intval($_GET['page']);
}
$limitStart = ($page - 1) * 10 + 1;
$limitEnd = $page * 10;

$query = 'SELECT * FROM data LIMIT ' . $limitStart . ',' . $limitEnd;

// etc.
?>
Coditor

Post Reply