Jump to content

Pagination question


music_lp90

Recommended Posts

Hi all, I've got a page that paginates results into 3 records per page and creates links for the total number of pages that exist. MY question is how can I modify my links so instead of creating a link to every page that exists, it only display links to first 10 pages and a link to display the next 10 pages.like this prev 1 2 3 4 5 6 7 8 9 10 next Next 10 PagesWhen someone clicks on next 10 pages then it looks like thisprev 11 12 13 14 15 16 17 18 19 20 next Next 10 Pagesand if possible I would like the Next 10 Pages to only show up when the user gets to the end of the links such as the 10th link, 20th link, 30th link, etc.Here's the code, the part for display page links is at the bottom.

<?php$dbh=mysql_connect ("localhost", "administrator", "Password") or die ('I cannot connect to the database because: ' . mysql_error());mysql_select_db ("dbName");//set variables$perpage = 3; 									// number per page to be displayed$count = mysql_query("SELECT * FROM news"); 	//count records$total = mysql_num_rows($count); 				// number of total records$pages = ceil($total / $perpage);				//number of pages $thispage = isset($_GET['pg'])?$_GET['pg']-1:0; //what page is user on$start = $perpage * $thispage; 					//what page to start on// --------------------------------------------------------------------//display records$result = mysql_query("SELECT * FROM news ORDER BY 'id' DESC LIMIT $start, 3");while($row = mysql_fetch_array( $result)) {   echo '<p class="sm_blk_bold">' .$row['date'] . "</p>";  echo "<p>";  echo $row['statement'];  echo "</p><br />";} //------------------------------------------------------------------------------//page links    print "Page ";	if ($thispage > 0) 	print " <a href='?pg=" . ($thispage) ."'>"."Prev "."</a>";    for ($i=0;$i<$pages;$i++)       if ($i==$thispage)         print " ".($i+1);       else         print " <a href='?pg=".($i+1)."'>".($i+1)."</a>";	if (($thispage + 1) !== $i) 	print " <a href='?pg=" . ($thispage + 2) ."'>"."Next "."</a>";mysql_close();

Thanks for any help! You guys have been a ton of help already!

Link to comment
Share on other sites

Try this, replace where your for loop is at the bottom with this code.

for ($i=0;$i<$pages;$i++) {  if ($i==$thispage)    print " ".($i+1);  else    print " <a href='?pg=".($i+1)."'>".($i+1)."</a>";    if (($thispage + 1) !== $i)      print " <a href='?pg=" . ($thispage + 2) ."'>"."Next "."</a>";}if (($thispage+1)%10==0) {  print " <a href='?pg=".($thispage+10).">Next 10 Pages</a>"}

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...