Недавно я сам сделал пагинатор, но подошел к нему совершенно по-другому. Я использовал php для генерации чисел, и у каждого номера (страницы) был тег с href, который был mywebsite.php? Page = x. Таким образом, вы можете использовать метод get, захватить номер страницы из URL и циклически проходить столько раз, сколько вы хотите, для количества отображаемых страниц.
Как говорится, существует более одного способа кожи кошки. Я предпочитаю метод передачи URL, потому что я могу держаться подальше от форм и идентификаторов в целом, делая так, чтобы пагинатор мог ходить туда, куда я решу (или сколько раз).
Вот снимок того, как я его генерировал. Надеюсь, это даст вам некоторые идеи!
/*PAGE NUMBERS*/
// ceil rounds a decimal up to the next integer
$pages=ceil(($totalrows-1)/$tablesize); //we subtract 1 from total rows because it counts 0
//(int) typecasts the $pages variable, so that it is divisible by an integer (ceil makes it a float)
$pages=(int)$pages;
//displays all the pages with their links
//if page count is less than 7 (the full paginator), display all pages
if($pages<=7){
for($i=1;$i<=$pages;$i++){
print "<a class='pages";
//add class current_page if necessary
if($page==$i){print " current_page";}
print "' href='index.php?page=";
print $i. "'>"." $i</a> "." "." ";
}
//if page count is more than 7
}else{
//if page # is less than 4, display pages up to 7, so that there are always 7 pages available (makes the buttons not jump around)
if($page<=4){
for($i=1;$i<=7;$i++){
print "<a class='pages";
//add class current_page if necessary
if($page==$i){print " current_page";}
print "' href='index.php?page=";
print $i. "'>"." $i</a> "." "." ";
}
//if page # is less than 4 away from the end, display pages $pages-7
}elseif($page>=$pages-3){
for($i=$pages-6;$i<=$pages;$i++){
//8,9,10,11,12,13,14,15
print "<a class='pages";
//add class current_page if necessary
if($page==$i){print " current_page";}
print "' href='index.php?page=";
print $i. "'>"." $i</a> "." "." ";
}
//if it's in between the ends, do this
}else{
for($i=1;$i<$pages+1;$i++){
//limit the number of visible pages to 7
if(($i>=$page-3)&&($i<=$page+3)){
print "<a class='pages";
//add class current_page if necessary
if($page==$i){print " current_page";}
print "' href='index.php?page=";
print $i. "'>"." $i</a> "." "." ";
}
}
}
}