virtualmysterious Posted June 26, 2009 Share Posted June 26, 2009 Dear members, I am facing a problem in my websites pagination, in index.php file i am using this php code. PageNavigation($pageno,$totalPages,$query); And in config.php i am using this code. function PageNavigation($pageno,$totalPages,$query){ ?> <table align="center" border="0" cellpadding="3" cellspacing="0"> <tr> <!--<td class="pager">Page:</td>--> <?php if($pageno!=1){ $hr = $query."pageno=1"; echo"<td class='pager'><a href='$hr' class='pager'>First</a></td>"; $a = $pageno-1; $hr = $query."pageno=".$a; echo"<td class='pager'><a href='$hr' class='pager'>Back</a></td>"; } $i = 1; while($i <= $totalPages){ $hr = $query."pageno=".$i; if($i == $pageno){ echo"<td class='pagerOn'><b>$i</b></td>"; }else{ echo"<td class='pager'><a href='$hr' class='pager'>$i</a></td>"; } $i++; } if($pageno!=$totalPages){ $a = $pageno+1; $hr = $query."pageno=".$a; echo"<td class='pager'><a href='$hr' class='pager'>Next</a></td>"; $hr = $query."pageno=".$totalPages; echo"<td class='pager'><a href='$hr' class='pager'>Last</a></td>"; } ?> <!--<td class="pager"> (<?php echo $totalPages;?> total)--> </tr> </table> <?php } ?> The problem is that, all page numbers is showing on index file. As example. 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 Next Previous But i want to change it with 10 pages on index file. And i want to change the pagination like this. As example. Previous 1 2 3 4 5 6 7 8 9 10..14 15 Next Please help me to change the pagination. I'll be very thankful to you. Link to comment https://forums.phpfreaks.com/topic/163740-solved-please-help-pagination-code-in-config-file/ Share on other sites More sharing options...
dzelenika Posted June 26, 2009 Share Posted June 26, 2009 You should change $i = 1; while($i <= $totalPages){ $hr = $query."pageno=".$i; if($i == $pageno){ echo"<td class='pagerOn'><b>$i</b></td>"; }else{ echo"<td class='pager'><a href='$hr' class='pager'>$i</a></td>"; } $i++; } to something like $i = ($pageno - 5) > 0 ? ($pageno - 5) : 1; while($i <= $totalPages && $i < $pageno + 5){ $hr = $query."pageno=".$i; if($i == $pageno){ echo"<td class='pagerOn'><b>$i</b></td>"; }else{ echo"<td class='pager'><a href='$hr' class='pager'>$i</a></td>"; } $i++; } Link to comment https://forums.phpfreaks.com/topic/163740-solved-please-help-pagination-code-in-config-file/#findComment-863986 Share on other sites More sharing options...
virtualmysterious Posted June 26, 2009 Author Share Posted June 26, 2009 Thanks brother..! Problem solved. Thank you so much. Link to comment https://forums.phpfreaks.com/topic/163740-solved-please-help-pagination-code-in-config-file/#findComment-864008 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.