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 ...
|
|||||||
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
|
|||
|
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 "; } 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> "; if($n == $pagenums_perline) // NEW (limit pages per line) { echo "<br>"; $n=1; } } $n++; // NEW (limit pages per line) } } |
|
|||
|
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 |