zohab Posted February 2, 2010 Share Posted February 2, 2010 Hi, I have pagination code and i have taken this code from http://www.plus2net.com/php_tutorial/demo_paging4.php Now in my project i have records more than 1000 and i am showing 5 records per page. So total pages are 190.This is disturbing page layout as per shown in image. I want google like pagination I want to show pages 1 2 3 4 5 6 7 8 9 10 Next When user click on Next then 2 3 4 5 6 7 8 9 Next When user click on Prev then 1 2 3 4 5 6 7 8 9 10 Next When user click on page number then that page record will be shown. I have attached zip file containing all pages required for pagination with an example. [attachment deleted by admin] Quote Link to comment Share on other sites More sharing options...
gwolgamott Posted February 2, 2010 Share Posted February 2, 2010 Was there a question there? Quote Link to comment Share on other sites More sharing options...
zohab Posted February 2, 2010 Author Share Posted February 2, 2010 Hi gwolgamott, The code i have attached contains pagination functionality as http://www.plus2net.com/php_tutorial/demo_paging4.php but i want to implement functionality as google like pagination as explain above. Quote Link to comment Share on other sites More sharing options...
gwolgamott Posted February 2, 2010 Share Posted February 2, 2010 I see, sorry about that. Hmmm... that's a bit of a simple yet complicated process actually... But after checking that site out.... http://www.plus2net.com/php_tutorial/php_paging_adv.php?start=8&p_f=8 Isn't that advance version he has up do what you wanted to do? Quote Link to comment Share on other sites More sharing options...
zohab Posted February 3, 2010 Author Share Posted February 3, 2010 Hi gwolgamott, thanks for advance php pagination site url. but it is not providing paginationthe way google provides. I want to show pages 1 2 3 4 5 6 7 8 9 10 Next 1.When user click on Next then 2 3 4 5 6 7 8 9 Next 2.When user click on Prev then 1 2 3 4 5 6 7 8 9 10 Next 3.When user click on page number then that page record will be shown. Quote Link to comment Share on other sites More sharing options...
gwolgamott Posted February 3, 2010 Share Posted February 3, 2010 Ah, well that is a bit more obtrusive to do. Can it be done yeah, but way too much time to do it for me unless I needed it. But if you understand php that sample code is a start and just change the action of the next link instead with perhaps a series of if statements that check current and next page of links... Here's a script that uses a database first to pull rows, but if you don't want to use that then it's not hard to retro-fit to your needs. I had this sitting someplace, and have forgotten where i got it from. I didn't write it so can't go through it in detail (Well I could, but it's not as easy if I wrote it.), but they may be a better start for you with already working on the other script too. <?php $limit = 10; $start = 1; $slice = 9; $q = "SELECT * FROM table"; $r = mysql_query($q, conn()); $totalrows = mysql_num_rows($r); if(!isset($_GET['page']) ¦¦!is_numeric($_GET['page'])){ $page = 1; } else { $page = $_GET['page']; } $numofpages = ceil($totalrows / $limit); $limitvalue = $page * $limit - ($limit); $q = "SELECT * FROM table LIMIT $limitvalue, $limit"; if ($r = mysql_query($q, conn())) { //loop results here while ($row = mysql_fetch_assoc($r)) { echo $row['column'].'<br />'; } if($page!= 1){ $pageprev = $page - 1; echo '<a href="'.$_SERVER['php_SELF'].'?page='.$pageprev.'">PREV</a> - '; }else{ echo "PREV - "; } if (($page + $slice) < $numofpages) { $this_far = $page + $slice; } else { $this_far = $numofpages; } if (($start + $page) >= 10 && ($page - 10) > 0) { $start = $page - 10; } for ($i = $start; $i <= $this_far; $i++){ if($i == $page){ echo "<u><b>".$i."</b></u> "; }else{ echo '<a href="'.$_SERVER['php_SELF'].'?page='.$i.'">'.$i.'</a> '; } } if(($totalrows - ($limit * $page)) > 0){ $pagenext = $page + 1; echo ' - <a href="'.$_SERVER['php_SELF'].'?page='.$pagenext.'">NEXT</a>'; }else{ echo " - NEXT"; } } ?> Quote Link to comment Share on other sites More sharing options...
zohab Posted February 4, 2010 Author Share Posted February 4, 2010 Thanks gwolgamott, Great work I am sorry but my project manager change the requirement. Now he want pagination functionality as follows. Suppose we have 30 pages ,we have to show 5 records per page Page 1 will show : 1 2 3 4 5 Next5 Page 2 will show : Prev5 6 7 8 9 10 Next5 Page 3 will show : Prev5 11 12 13 14 15 Next5 Quote Link to comment Share on other sites More sharing options...
gwolgamott Posted February 4, 2010 Share Posted February 4, 2010 $limit = 10; I tihnk changing that variable may help determine that. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.