Jump to content

if ($pages < $page - 3 || $pages > $page + 3) return;


jirimail

Recommended Posts

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

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++;
}
}

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..

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.