unemployment Posted July 21, 2011 Share Posted July 21, 2011 I want to make some google like pagination. Prevous 1 ... 4 5 6 7 8 ... 124 Next Can anyone tell me how to going about doing pagination like this? I'm not sure where I should start. Quote Link to comment https://forums.phpfreaks.com/topic/242565-google-like-pagination/ Share on other sites More sharing options...
TeNDoLLA Posted July 21, 2011 Share Posted July 21, 2011 http://tinyurl.com/3odyhwv Quote Link to comment https://forums.phpfreaks.com/topic/242565-google-like-pagination/#findComment-1245767 Share on other sites More sharing options...
AdRock Posted July 21, 2011 Share Posted July 21, 2011 $count="SELECT COUNT(*) FROM yourtable ORDER BY id DESC"; $sql="SELECT * FROM `yourtable` ORDER BY id DESC"; // Perform a query getting back a MySQLResult object $res = $db->query($count); $result = $db->query($sql); //get the number of rows in datatbase $getresult = $result->size(); $numrows = $res->fetchrow(); if(isset($_GET['pagenum'])) { $page = $_GET['pagenum']; } else { $page = 1; } $entries_per_page = 1; $total_pages = ceil($numrows[0]/$entries_per_page); $offset = (($page * $entries_per_page) - $entries_per_page); and to call the function to display the links pagination($$total_pages,$page); This is the function to create the paging function pagination($total_pages,$page){ // Global variable passed between the pages global $webpage; // Maximum number of links per page. If exceeded, google style pagination is generated $max_links = 6; $h=1; if($page>$max_links){ $h=(($h+$page)-$max_links); } if($page>=1){ $max_links = $max_links+($page-1); } if($max_links>$total_pages){ $max_links=$total_pages+1; } echo '<div class="page_numbers"> <ul>'; if($page>"1"){ echo '<li class="current"><a href="/'.$webpage.'/1">First</a></li> <li class="current"><a href="/'.$webpage.'/'.($page-1).'">Prev</a></li> '; } if($total_pages!=1){ for ($i=$h;$i<$max_links;$i++){ if($i==$page){ echo '<li><a class="current">'.$i.'</a></li>'; } else{ echo '<li><a href="/'.$webpage.'/'.$i.'">'.$i.'</a> </li>'; } } } if(($page >="1")&&($page!=$total_pages)){ echo '<li class="current"><a href="/'.$webpage.'/'.($page+1).'">Next</a></li> <li class="current"><a href="/'.$webpage.'/'.$total_pages.'">Last</a></li>'; } echo '</ul> </div>'; } the css .page_numbers { width:100%; background:#fff9f0; overflow:hidden; position:relative; padding:50px 0; } .page_numbers ul { clear:left; float:left; list-style:none; margin:0; padding:0; position:relative; left:50%; text-align:center; } .page_numbers ul li { display:block; float:left; list-style:none; margin:1px; padding:0; position:relative; right:50%; background: #a8a189; width:25px; } .page_numbers ul li a { display:block; background: #fff; border: 1px solid #a8a189; padding:3px 6px; text-decoration: none; color: #7a7564; font:bold 11px arial, verdana,sans-serif; } any probs give us a shout Quote Link to comment https://forums.phpfreaks.com/topic/242565-google-like-pagination/#findComment-1245785 Share on other sites More sharing options...
unemployment Posted July 21, 2011 Author Share Posted July 21, 2011 Perhaps i'll impliment your method. I just made another form of pagination for my site, but it's not the greatest. I'm finally starting to understand how it works. Can someone please explain to me what -> that means in php? Quote Link to comment https://forums.phpfreaks.com/topic/242565-google-like-pagination/#findComment-1245839 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.