Hello I am working on a auto index script, It can show 10 files per page from a folder. But now I am facing a problem. Page navigation should work like <<First 1 2 3 4 5 6 Last>> or <<First 1 2 3 4 5 . . . 8 9 Last>> But the problem it its showing all pages like i have 800 files in the folder now its showing all 1 - 80 pages. Some one please help me to fix this problem. Here i am pasting my present navigation code: <?php if($_GET["offset"]=="0") { echo '<a data-mini="true" data-role="button" data-inline="true" data-theme="d">First << </a>'; } else { echo '<a data-mini="true" data-role="button" data-inline="true" data-icon="arrow-l" data-theme="a" href="index.php?path='.$path.'&offset=0">First </a>'; echo '<a data-mini="true" data-role="button" data-inline="true" data-theme="a" href="downloads.php?view=index.php?path='.$path.'&offset='.$prev.'"><< </a>'; } for ($i=1; $i <= $pages; $i++) { $newoffset=$limit*($i-1); if ($newoffset != $offset) { ?> <a data-mini="true" data-role="button" data-inline="true" data-theme="a" href="index.php?path=<?php echo $path = htmlspecialchars($_GET["path"], ENT_QUOTES); $path; ?>&offset=<?php print $newoffset; ?><?php print $query; ?>"> <?php print $i; ?> </a> <?php } else { ?> <?php echo '<a data-mini="true" href="#" data-role="button" data-inline="true" data-theme="d">'.$i.'</a>'; } } if($offset==$lastnum) { echo '<a data-mini="true" data-role="button" data-inline="true" data-theme="d"> >>'; echo ' Last</a>'; } else { echo '<a data-mini="true" data-role="button" data-inline="true" data-theme="a" href="index.php?path='.$path.'&offset='.$next.'"> >></a>'; $lastlink = $totalnum-1; echo '<a data-mini="true" data-role="button" data-inline="true" data-icon="arrow-r" data-theme="a" href="index.php?path='.$path.'&offset='.$lastlink.'"> Last</a></div>'; } } } freddyShowNav($offset,$limit,sizeof($files),""); echo $page; echo '<br/>'; PHP:
I would suggest that you build your web application on top of some popular framework. These frameworks support by default the pagination feature, so you don't have to reinvent the wheel. Try http://www.truthsource.net/wp/php-pagination-class/ if you need to implement a pagination class, or you can browse the code to see how it was implemented.