Page Numbers

This is a discussion on Page Numbers within the alt.comp.lang.php forums, part of the PHP Programming Forums category; Hi all, I have a results page which displays 25 records per page I never thought about it in development ...


Go Back   Usenet Forums > PHP Programming Forums > alt.comp.lang.php

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 12-07-2005
Iain
 
Posts: n/a
Default Page Numbers

Hi all,

I have a results page which displays 25 records per page I never thought
about it in development but I added page numbers at the bottom so you can
jump between the page. However the number of records in the whole database
has grown, so I have about 55 pages of records now - which will just keep
growing.

I decided to add a line break after each instance of 20 pages, so I should
get 20 pages per line. This works for under 20 pages but as soon as I go to
page 20 or above it stops working.

My code is below and I am not sure why it doesn't work correctly!

Any guidance would greatly be appreciated.

TIA

// Figure out the total number of results in DB:
$total_results = mysql_result(mysql_query("SELECT COUNT(*) as Num FROM
tbl_request WHERE recordstatus='$record'"),0);

// Figure out the total number of pages. Always round up using ceil()
$total_pages = ceil($total_results / $max_results);

$pagenums_perline = 20;// NEW (limit pages per line)
$n = 1;// NEW (limit pages per line)

// Build Page Number Hyperlinks
echo "Select a Page";
echo "<br>";
for($i = 1; $i <= $total_pages; $i++)
{
if(($page) == $i)
{
echo "$i&nbsp;";
}
else
{
$sortby = $_GET['sortby'];
if(empty($sortby))
{
$sortby = ID;
}
$dir = $_GET['dir'];
if(empty($dir))
{
$dir = ASC;
}
echo "<a
href=\"".$_SERVER['PHP_SELF']."?page=$i&record=$record&sortby=$sortby&dir=$dir\ ">$i</a>&nbsp;";
if($n == $pagenums_perline) // NEW (limit pages per line)
{
echo "<br>";
$n=1;
}
}
$n++; // NEW (limit pages per line)
}
}


Reply With Quote
  #2 (permalink)  
Old 12-07-2005
Stefan Wallentowitz
 
Posts: n/a
Default Re: Page Numbers

Am Wed, 07 Dec 2005 19:38:11 +0000 schrieb Iain:

> Hi all,

Hi!
> I decided to add a line break after each instance of 20 pages, so I should
> get 20 pages per line. This works for under 20 pages but as soon as I go to
> page 20 or above it stops working.


Perhaps you should check your brackets respective bodies. To me it seems
like the "if($n== [..] $n++;"-part is placed in a way that it is only
executed for pages unequal the actual, so that reaching the twntieth page
ends in not executing this part.

Greetings,
Stefan

Reply With Quote
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT +1. The time now is 08:55 PM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0