Salis Posted July 14, 2007 Share Posted July 14, 2007 All right well it's been a while since I've done Pagination. And so far so good, but I'm in need of a little help with the links. Right now all links are show on the page but I really don't want to do that. What I would like are links based on pages. I want to show some thing like below: << 4 5 [6] >> I want to group the links according to the pages so if I'm on page 1, 2 or 3 those links are show however if I click the >> link a new group of 4, 5 and 6 are show and so on. Any idea on how to do this? Thanks all phpfreaks Link to comment https://forums.phpfreaks.com/topic/59895-solved-mysql-paged-results-php-coded-links/ Share on other sites More sharing options...
pocobueno1388 Posted July 14, 2007 Share Posted July 14, 2007 Could you post your code that currently generates the links? Link to comment https://forums.phpfreaks.com/topic/59895-solved-mysql-paged-results-php-coded-links/#findComment-297863 Share on other sites More sharing options...
Salis Posted July 14, 2007 Author Share Posted July 14, 2007 Sure. This is a "simulated Query" by the way. If that makes since. I find it point less to query when I'm trying to create the links... Any way, This is what I have so far. I think I may need to use 2 for statements to get this working but I'm not sure how to generate the next group. <?php $xPage = (!is_numeric($_GET['page'])) ? 1 : $_GET['page']; $Total_Posts = 54; // Simulated Query Row count $Posts_Per_Page = 5; $Total_Pages = ceil($Total_Posts / $Posts_Per_Page); $Start_Pull = ($xPage -1) * $Posts_Per_Page; // - $Posts_Per_Page; $SQL_LIMIT = "LIMIT $Start_Pull, $Posts_Per_Page"; echo "You're on page $xPage. There are a total of $Total_Posts posts on $Total_Pages pages. The SQL LIMIT is "$SQL_LIMIT".<br><br>"; for( $i = 1; $i <= 5; $i++ ) { if( $i == $xPage ) { echo "$i "; } else { echo " <a href='{$_SERVER['PHP_SELF']}?page=$i'>$i</a> "; } } ?> Link to comment https://forums.phpfreaks.com/topic/59895-solved-mysql-paged-results-php-coded-links/#findComment-297867 Share on other sites More sharing options...
infid3l Posted July 14, 2007 Share Posted July 14, 2007 <?php $page = $_GET['page']; $show = 3; echo "<< "; if ($page > $show/2) { $start = $page-round($show/3);; } else { $start = $page; } for ($i=$start;$i<$start+$show;$i++) { if ($i == $page) { print " [$i] "; } else { print " $i "; } } echo " >>"; ?> Took me a while to get it working, a bit tricky Try this on a separate page and see if this is what you're looking for. edit: changed it a bit to make it dynamic. demo: http://www.infamousx.com/test.php?page=4 Link to comment https://forums.phpfreaks.com/topic/59895-solved-mysql-paged-results-php-coded-links/#findComment-297870 Share on other sites More sharing options...
pocobueno1388 Posted July 14, 2007 Share Posted July 14, 2007 Hah, this took me a few minutes as well...so I might as well post it. <?php $xPage = 3; $prev_page = $xPage-1; $next_page = $xPage+1; $prev_group = $xPage-3; $next_group = $xPage+3; //Generate Links echo "<a href='{$_SERVER['PHP_SELF']}?page=$prev_group'><< </a>"; echo "<a href='{$_SERVER['PHP_SELF']}?page=$prev_page'>$prev_page </a>"; echo "[$xPage] "; echo "<a href='{$_SERVER['PHP_SELF']}?page=$next_page'>$next_page </a>"; echo "<a href='{$_SERVER['PHP_SELF']}?page=$next_group'>>></a> "; ?> It might take a little bit more coding...but it works =] Link to comment https://forums.phpfreaks.com/topic/59895-solved-mysql-paged-results-php-coded-links/#findComment-297871 Share on other sites More sharing options...
Salis Posted July 14, 2007 Author Share Posted July 14, 2007 Hey cool. Thanks guys. Different approach than me. This helps a lot. Link to comment https://forums.phpfreaks.com/topic/59895-solved-mysql-paged-results-php-coded-links/#findComment-297874 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.