I have successfully implemented a pager for my script thanks to reading tutorials...the problem is i have like 160 pagination links, (lost of records in the database) what i want to do is instead of showing links to all 160 pages, i want to show ten page links at a time...then a link saying "next 10" i just can't figure out the logic or what to call it to search in google
y=0 if(x=0;x<10;x++) { //display the first ten results y++; } PHP: pass along the y variable by post, get, or request and then display the next results after y
The records are in a database? If its SQL.. A query such as SELECT * FROM tablename LIMIT 10; Code (markup): Should work fine, and you can also use ORDER BY to organize them. To show the next 10 records it would be SELECT * FROM tablename LIMIT 10, 20; Code (markup):
I'm not sure this is what you are looking for but maybe can help if (!$start) $start=0; $end = $start + 10; $next = $end+1; print("<a href="linklister.php?start=$next">Next >></a>"); $eredm = mysql_query("SELECT * FROM table LIMIT $start,$end") or die(mysql_error()); while($sor=@mysql_fetch_array($eredm)){ // do whatever you want } Code (markup): hope it helps a bit
f(!isset($_GET['page'])) { $page_num = 1; } else { $page_num = $_GET['page']; } define("RECORDS_PER_PAGE", 100); $starting_offset = ($page-1) * RECORDS_PER_PAGE; $query = "SELECT * FROM my_table LIMIT ".$starting_offset.", ".RECORDS_PER_PAGE; Code (markup): That should work OK.
Oops. $starting_offset = ($page-1) * RECORDS_PER_PAGE; Code (markup): Should really be $starting_offset = ($page_num-1) * RECORDS_PER_PAGE; Code (markup):
and this will give me the following? previous 1 2 3 4 5 6 7 8 9 10 next 10 previous 10 11 12 13 14 15 16
hey man.. Here is a good tut for it....http://www.webpronews.com/expertarticles/2006/06/20/php-pagination-with-mysql I used it and got it working.....although I did modify it a little ......so if you need help with it let me know.
$page = 1; $limit_begin = 0; $limit_end = MAX_DOCUMENTS_PER_PAGE; //page id if( !empty($_GET['page']) ){ settype($_GET['page'],"integer"); $page = $_GET['page']; $limit_begin = ($page-1)*$limit_end; } $query = "SELECT SQL_CALC_FOUND_ROWS field, other_field FROM some_table LIMIT ".$limit_begin.", ".$limit_end; $result = $db->query($query); while($row = $db->fetch_array($result)){ ..... } if($db->num_rows($result)){ $t = $db->query_first("SELECT FOUND_ROWS()"); $pages = $t['FOUND_ROWS()']/$limit_end; if( (int)$pages - $pages <0 ) $pages = (int)$pages+1; if( $pages != 1 ){ for($i=1; $i<=$pages; $i++ ){ echo ( $i != $page ) ? " <a href=\"...&_GET['page']=".$i."\">".$i."</a> " : " ".$i." "; if( $i != $pages ) echo " | "; } } } PHP: