I'm trying to do the typical paging seen on this forum. I'm partially finished but I'm stuck at limiting the page numbers per page. By that I mean is if I have 200 records to be displayed at 5 pages per page, then it would be something like 1,2,3,4,5,6,7,8...40.
I want to have it so it says: Pages (3): « 1 [2] 3 »
But I would like to go around my code. I've read just about every post here on paging, and while yes they go over how to do this, for some reason, I can't apply it to my code. Maybe I can get some help. Here's my code (only the portion that does paging):
# $SnippetCount["snippet_count"] is the RecordCount for the record set
$number_of_pages = ceil($SnippetCount["snippet_count"]/$perpage);
$ax = 0; // tempcounter used to display page numbers
$current_page = ceil($from/$perpage)+1; // determine current page the user is on
// Generating Page Numbers
for($i=1; $i<=$number_of_pages; $i++) {
if ($i==$current_page) {
echo "<font size=\"6\"class=\"GeneralLargeText\"><strong>$i</strong></font> ";
$ax = $ax + $perpage;
continue;
} else {
echo "<a href=\"".$_SERVER['SCRIPT_NAME']."?from=$ax&perpage=$perpage&orderby=".translate_fieldwords($orderby)."&ordertype=$ordertype\"><font class=\"TextSpecialMessage2\">$i</font></a> ";
$ax = $ax + $perpage;
}
}
// Modifying $prev and $next variables so they don't go out of bounds.
if($prev < -1) $prev=0;
if($next >= $SnippetCount["snippet_count"]) $next = $from;
// [ Previous | Next ]
echo "[ ";
if($current_page==1)
echo "<a href=\"".$_SERVER['SCRIPT_NAME']."?from=$next&perpage=$perpage&orderby=".translate_fieldwords($orderby)."&ordertype=$ordertype\"><font class=\"TextSpecialMessage2\">Next</font></a> ";
elseif($current_page>1 && $current_page<$number_of_pages){
echo "<a href=\"".$_SERVER['SCRIPT_NAME']."?from=$prev&perpage=$perpage&orderby=".translate_fieldwords($orderby)."&ordertype=$ordertype\"><font class=\"TextSpecialMessage2\">Previous</font></a> ";
echo "<a href=\"".$_SERVER['SCRIPT_NAME']."?from=$next&perpage=$perpage&orderby=".translate_fieldwords($orderby)."&ordertype=$ordertype\"><font class=\"TextSpecialMessage2\">Next</font></a> ";
}
elseif($current_page==$number_of_pages)
echo "<a href=\"".$_SERVER['SCRIPT_NAME']."?from=$prev&perpage=$perpage&orderby=".translate_fieldwords($orderby)."&ordertype=$ordertype\"><font class=\"TextSpecialMessage2\">Previous</font></a> ";
echo "]";
So for this, if I had 116 records, and if I was on page one at 5 records per page, the above would display:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 [ Next ]
Any help is greatly appreciated. Thanks!