CODE
<?php
## This is a very basic & simple to intergrate pagination script
## which will split your news / comments etc up into different pages,
## so that you dont have a million entries on the one page.
## written by paul fraser @ paulOr.net
$maxitems = 5; // how many items shall we show at once?
$page_num = $_GET['page_num']; // get the current page number.
if(empty($page_num)) {
$page_num = 1; // if we cant find the page number, lets make it #1 :)
}
$limits = ($page_num - 1) * $maxitems;
// Grab everything we are needing out of the database and count everything up. yum!
$sql = mysql_query("SELECT * FROM `news` ORDER BY `id` DESC LIMIT ".$limits.",".$maxitems."") or die(mysql_error());
$totalres = mysql_result(mysql_query("SELECT COUNT(id) AS tot FROM `news` ORDER BY `id` DESC"),0);
$totalpages = ceil($totalres / $maxitems);
// Now lets loop through it and print it all out.
while($r = mysql_fetch_array($sql)) {
echo "<p>".$r['title']."</p>";
}
// Create prev and next links.
$lastpage = $page_num - 1;
$nextpage = $page_num + 1;
echo "<ul id=\"pagination\">";
// if this is the first page, then kill the back page link, else lets keep it
if($page_num == 1) {
echo "<li><</li>";
} else {
echo "<li><a href=\"/news/page/$lastpage/\"><</a></li>";
}
// list all of the pages.
for($i = 1; $i <= $totalpages; $i++) {
if($page_num == $i) {
// kill the link to the CURRENT page
// and we can style it different so people know they are here.
echo "<li class=\"active\">$i</li>";
} else {
echo "<li><a href='/news/page/$i/'>$i</a></li>";
}
}
// if this is the last page, then kill the next page link, else lets keep this too.
if($page_num == $totalpages) {
echo "<li>></li>";
} else {
echo "<li><a href=\"/news/page/$nextpage/\">></a></li>";
}
echo "</ul>";
?>
## This is a very basic & simple to intergrate pagination script
## which will split your news / comments etc up into different pages,
## so that you dont have a million entries on the one page.
## written by paul fraser @ paulOr.net
$maxitems = 5; // how many items shall we show at once?
$page_num = $_GET['page_num']; // get the current page number.
if(empty($page_num)) {
$page_num = 1; // if we cant find the page number, lets make it #1 :)
}
$limits = ($page_num - 1) * $maxitems;
// Grab everything we are needing out of the database and count everything up. yum!
$sql = mysql_query("SELECT * FROM `news` ORDER BY `id` DESC LIMIT ".$limits.",".$maxitems."") or die(mysql_error());
$totalres = mysql_result(mysql_query("SELECT COUNT(id) AS tot FROM `news` ORDER BY `id` DESC"),0);
$totalpages = ceil($totalres / $maxitems);
// Now lets loop through it and print it all out.
while($r = mysql_fetch_array($sql)) {
echo "<p>".$r['title']."</p>";
}
// Create prev and next links.
$lastpage = $page_num - 1;
$nextpage = $page_num + 1;
echo "<ul id=\"pagination\">";
// if this is the first page, then kill the back page link, else lets keep it
if($page_num == 1) {
echo "<li><</li>";
} else {
echo "<li><a href=\"/news/page/$lastpage/\"><</a></li>";
}
// list all of the pages.
for($i = 1; $i <= $totalpages; $i++) {
if($page_num == $i) {
// kill the link to the CURRENT page
// and we can style it different so people know they are here.
echo "<li class=\"active\">$i</li>";
} else {
echo "<li><a href='/news/page/$i/'>$i</a></li>";
}
}
// if this is the last page, then kill the next page link, else lets keep this too.
if($page_num == $totalpages) {
echo "<li>></li>";
} else {
echo "<li><a href=\"/news/page/$nextpage/\">></a></li>";
}
echo "</ul>";
?>
More @ paulOr.net

Sign In
Register
Help





MultiQuote