mat3000000 Posted July 18, 2012 Share Posted July 18, 2012 Hi, I think there should be a very easy way to do what I want to do. I just can't think of it! I have the number of pages returned in a variable called $pages. I want to add a link to every page like at the bottom of google. Example, there are three pages, links echoed like: 1 2 3 Thanks in advance Link to comment https://forums.phpfreaks.com/topic/265891-help-with-paged-results/ Share on other sites More sharing options...
lordshoa Posted July 18, 2012 Share Posted July 18, 2012 should the var not be an array ? But you need to look at: pagination Link to comment https://forums.phpfreaks.com/topic/265891-help-with-paged-results/#findComment-1362394 Share on other sites More sharing options...
andrew_biggart Posted July 18, 2012 Share Posted July 18, 2012 I used this tutorial to get my head around how php works. Maybe you will find it as useful as I did. http://www.phpeasystep.com/phptu/29.html Link to comment https://forums.phpfreaks.com/topic/265891-help-with-paged-results/#findComment-1362398 Share on other sites More sharing options...
ManiacDan Posted July 18, 2012 Share Posted July 18, 2012 $pages = 10; $currentPage = 3; for ( $p = 1; $p <= $pages; $p++ ) { if ( $p == $currentPage ) { echo " <b>{$currentPage}</b> "; } else { echo " <a href='whateverPage.php?page={$p}'>{$p}</a> "; } } Link to comment https://forums.phpfreaks.com/topic/265891-help-with-paged-results/#findComment-1362453 Share on other sites More sharing options...
mat3000000 Posted July 19, 2012 Author Share Posted July 19, 2012 Absolutely perfect script, worked a treat. Thanks! Link to comment https://forums.phpfreaks.com/topic/265891-help-with-paged-results/#findComment-1362656 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.