3
Contributors
3
Replies
4
Views
10 Years
Discussion Span
Last Post by Puckdropper
0

Im assuming your getting the data from a Database. Ill use the example below on PHP/MySQL setup.

You should use something like this;

<?php

$display=10; // The number of records on each page
$start=0;

$query="SELECT COUNT(*) FROM table_name";

$result=mysql_query($query);

$row=mysql_fetch_array($result, MYSQL_NUM);
$num_records=$row[0];

//Calculate # of pages required.
// If the number of returned records is greater than the $display //number then it will create more pages.

if($num_records > $display) {
$num_pages=ceil($num_records/$display);
}else{
$num_pages=1;
}

PLACE HERE YOUR SCRIPT TO QUERY THE DATABASE AND DISPLAY THE RESULTS.

// Here we make the links to other pages
if($num_pages >1) {

echo '<BR/><p>';

//Find what page the script is on
$current_page=($start/$display) +1;

// IF NOT 1st Make a previous button
if($current_page !=1) {
echo '<a href="page_title.php?s='. ($start - $display) .'$np=' . $num_pages.'">Prev</a>';
}

// IF NOT LAST PAGE MAKE A NEXT BUTTON
if($current_page !=$num_pages) {
echo '<a href="page_title.php?s='.($start + $display).'&np='.$num_pages.'">Next</a>';
}
echo '</p>';
}
?>

Hope this helps. PM me if you have any problems.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.