I have a script running that sets page numbers and so far it has worked quite well for me. No real complaints.
The Script is as follows:
// If current page number, use it
// if not, set one!
if(!isset($_GET['page'])){
$page = 1;
} else {
$page = $_GET['page'];
}
// Define the number of results per page
$max_results = 10;
// Figure out the limit for the query based
// on the current page number.
$from = (($page * $max_results) - $max_results);
// Figure out the total number of results in DB:
$total_results = mysql_result(mysql_query("SELECT COUNT(*) as Num FROM $table"),0);
// Figure out the total number of pages. Always round up using ceil()
$total_pages = ceil($total_results / $max_results);
// Build Previous Link
if($page > 1){
$prev = ($page - 1);
echo "<a href=\""
.$_PHP_SELF
."?page=$prev\">"
."<< Previous</a> ";
}
for($i = 1; $i <= $total_pages; $i++){ // Builds page numbers
if(($page) == $i){
echo "$i | ";
} else {
echo "<a href=\""
.$_PHP_SELF
."?page=$i\">$i</a> | ";
}
}
// Build Next Link
if($page < $total_pages){
$next = ($page + 1);
echo "<a href=\""
.$_PHP_SELF
."?page=$next\">Next >></a>";
}
Now the problem is I was using the script to page out an adminstration page for some items but it's 70+ pages! yikes! :eek:
Of course it doesn't wrap around and extends the page waaay farther than I would like it to. And even if it didn't wrap around cosmetically it doesn't look neat. Page nunmbering schemes that go something like
How can I achieve this amazing feat? Thanks in advance.