jirimail Posted May 4, 2007 Share Posted May 4, 2007 Hey guys, hope someone could help me with this. Im guite new to php. Actully just doing it to customize some script on my server. I need to show only few pages on my site, so i have this script wich it does for me, but only on one side: if ($pages < $page-3) return; but need add to it the other side as well: ($pages > $page+3) When i tried elseif, that didnt work.. Here is the whole script: function page($url) { global $page; $pages=1; for ($starter=0; $this->total>$starter; $starter+=$this->limit) { if ($pages != $page) echo "<a href=\"".$url.$pages."\" class=\"page\">$pages</a> \n"; else echo "<b>[ $pages ]</b> \n"; $pages++; if ($pages < $page-3) return; } } Anyone could help? Im honestly lost.. Thank you Jiri Quote Link to comment https://forums.phpfreaks.com/topic/49950-pagination-need-simple-help-please/ Share on other sites More sharing options...
Corona4456 Posted May 21, 2007 Share Posted May 21, 2007 I'm not quite sure what you mean. Could you elaborate a little more? By the looks of it... it seems like you are trying to show a range of pages according to the current page. For example: If you are on page 5 then you want to show 3 4 [5] 6 7 If you are on page 7 then you want to show 5 6 [7] 8 9 Am I correct in assuming this? Quote Link to comment https://forums.phpfreaks.com/topic/49950-pagination-need-simple-help-please/#findComment-258595 Share on other sites More sharing options...
john010117 Posted May 21, 2007 Share Posted May 21, 2007 Just do another if statement... PHP process a script until it reaches the first TRUE elseif statement, and stops there. But if you put an if there instead, the script will keep on processing all the statements that are TRUE. Quote Link to comment https://forums.phpfreaks.com/topic/49950-pagination-need-simple-help-please/#findComment-258603 Share on other sites More sharing options...
Guest JMitchell Posted May 21, 2007 Share Posted May 21, 2007 do you mean only include count for group of pages surrounding the page? $mid = $this->limit / 2; $starter = ($page >= $mid)?($page - $mid):0; $ender = (($starter + $this->limit)>$this->total)?$this->total:($page + $mid); for (; $starter <= $ender; $starter++) { Quote Link to comment https://forums.phpfreaks.com/topic/49950-pagination-need-simple-help-please/#findComment-258627 Share on other sites More sharing options...
JakeTheSnake3.0 Posted May 22, 2007 Share Posted May 22, 2007 <?php // Where $pages is an array which holds the links for each corresponding page number // Where $currPage is the current page that the user has selected // Where $pagesLimit is the maximum range of pages available to be selected by the user....i.e., 1 2 [3] 4 5 <- $pagesLimit = 5 // The math you'll have to use to figure out the start page and end page will be more conviluded considering you may enter in an odd number of pages...so you'll have to figure that part out. function generateLinks($pages, $currPage, $pagesLimit) { $startPage = $currPage - ($pagesLimit/2); $endPage = $currPage + ($pagesLimit/2); for($i=$startPage; $i<$endPage; $i++) { if ($i != $currPage) { echo "<a href=\"".$pages[$i]['url']."\" class=\"page\">$i</a> \n"; } else { echo "<b>[ $i ]</b> \n"; } } } ?> Quote Link to comment https://forums.phpfreaks.com/topic/49950-pagination-need-simple-help-please/#findComment-258721 Share on other sites More sharing options...
Guest JMitchell Posted May 22, 2007 Share Posted May 22, 2007 JakeTheSnake, your code will not work when currPage = 0 or currPage = lastPage - pagesLimit as its going to generate invalid pages which you cant go to. Quote Link to comment https://forums.phpfreaks.com/topic/49950-pagination-need-simple-help-please/#findComment-258772 Share on other sites More sharing options...
JakeTheSnake3.0 Posted May 22, 2007 Share Posted May 22, 2007 So fix it - I'm only giving you a starting point. Quote Link to comment https://forums.phpfreaks.com/topic/49950-pagination-need-simple-help-please/#findComment-259037 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.