jirimail Posted May 4, 2007 Share Posted May 4, 2007 Hope someone could help, should be easy I have this code to limit number of shown pages for my pagination, but it doesnt work. Any other ideas how to set condiditin AND codition?? As in this code: if ($pages < $page - 3 || $pages > $page + 3) return; The whole script is: should work, but it doest, going mad from it ??? 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 || $pages > $page + 3) return; } } Link to comment https://forums.phpfreaks.com/topic/49968-if-pages-page-3-pages-page-3-return/ Share on other sites More sharing options...
ToonMariner Posted May 4, 2007 Share Posted May 4, 2007 if ($pages > $page - 3 && $pages < $page + 3) return; Link to comment https://forums.phpfreaks.com/topic/49968-if-pages-page-3-pages-page-3-return/#findComment-245286 Share on other sites More sharing options...
jirimail Posted May 4, 2007 Author Share Posted May 4, 2007 Thank you for that, but it seems that still only one half of the line is working.. I keeps ignoring the left side of the script.. Any onter suggestions?? Link to comment https://forums.phpfreaks.com/topic/49968-if-pages-page-3-pages-page-3-return/#findComment-245303 Share on other sites More sharing options...
taith Posted May 4, 2007 Share Posted May 4, 2007 ya... as soon as that line goes true... it stops the function entirely... you cannot use return; for that... you'd need to scrap that, and use continue; Link to comment https://forums.phpfreaks.com/topic/49968-if-pages-page-3-pages-page-3-return/#findComment-245305 Share on other sites More sharing options...
jirimail Posted May 4, 2007 Author Share Posted May 4, 2007 continue and than? another if? Im not so advanced in php, normally it takes ma a day, to customize simple script Link to comment https://forums.phpfreaks.com/topic/49968-if-pages-page-3-pages-page-3-return/#findComment-245310 Share on other sites More sharing options...
taith Posted May 4, 2007 Share Posted May 4, 2007 basically... continue; tells the for() to stop what its doing, and start the loop over again... which, in this case, should cut off either end of the numbers... function page($url) { global $page; $pages=1; for($starter=0; $this->total>$starter; $starter+=$this->limit) { if ($pages < $page-3 && $pages > $page+3) continue; if ($pages != $page) echo "<a href=\"".$url.$pages."\" class=\"page\">$pages</a> \n"; else echo "<b>[ $pages ]</b> \n"; $pages++; } } Link to comment https://forums.phpfreaks.com/topic/49968-if-pages-page-3-pages-page-3-return/#findComment-245312 Share on other sites More sharing options...
jirimail Posted May 4, 2007 Author Share Posted May 4, 2007 Ok, i think i start understanding The thing is that this first script shows all the pages 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++; } } And than i though, if i add this code that should cut off the rest of the pages and shows etc: 5 6 7 [8] 9 10 11 if ($pages < $page - 3 && $pages > $page + 3) return; but it still goes: 1 2 3 4 5 ...65 [66] 67 68 still not taking care of the first pages.. Link to comment https://forums.phpfreaks.com/topic/49968-if-pages-page-3-pages-page-3-return/#findComment-245322 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.