Hi friends,

I have a site, where I want to limit the number of pages being viewed.
example:
1 | 2 | 3 | 4 | 5 | 5 | 7 | 8 | 9 | 10 | 11

want to reduce this to:

1 | 2 | 3 | 4 | ... | 10 | 11

I have the code but is giving headaches.

if(!empty($_GET[Start])) 
{ 
   $Start = $_GET[Start]; 
} 
else 
{ 
   $Start = '0'; 
} 

// limit of  links per page 
$ByPage = '13'; 

$rnav = mysql_query($qnav) or die(mysql_error()); 
      $rows = mysql_num_rows($rnav); 


         if($rows > $ByPage) 
         { 


                                  $ListingTable .=  "<table class=\"tlistnav\" border=0 cellspacing=0 align=center width=100% >"; 
            $ListingTable .= "<tr><td align=center><font face=verdana size=2> | "; 

            $pages = ceil($rows/$ByPage); 
         $pagesLimit = 10;//Limit of pages  

         $lowAllow = (int)($Start - ($pagesLimit / 2));  
            $start = ($lowAllow <= 0) ? 1 : $lowAllow;  
            $aboveAllow = $start + $pagesLimit;  
            $until = ($aboveAllow > $pages) ? $pages : $aboveAllow;  

            for($i = $start; $i <= $until; $i++)  
            { 
               $PageStart = $ByPage*$i; 

               $i2 = $i + 1; 

               if($PageStart == $Start) 
               { 
                  $links[] = " <span class=CurrPageIdx>$i2</span>\n\t "; 
               } 
               elseif($PageStart < $rows) 
               { 
$links[] = " <a class=BlackLink href=\"search.php?Start=$PageStart&c=$_GET[c]&s=$_GET[s]&search_kw=$_GET[search_kw]&CategoryID=$_GET[CategoryID]&search_district=$_GET[search_district]&search_place=$_GET[search_place]&search_city=$_GET[search_city]&PostID=$_GET[PostID]&zip=$_GET[zip]&old=$_GET[old]\">$i2</a>\n\t ";    

               } 
            } 

            $links2 = implode(" | ", $links); 

            $ListingTable .= $links2; 


            $ListingTable .= "| </td></tr>"; 
            //tablefix added </tr> to tlisnav 

            $ListingTable .= "</table><br><br>\n"; 

         } 
         else  // rows <= bypage (no navbar required) 
         { 
          $ListingTable .= "<br><br>\n"; 
         }  

Unfortunately the code is giving error, because the first page ( 1 ) does not appear, and when I click on page two so now appears 9 | 10 | 11 and will not appear on the page 1 | or later.
Testing with a limit of 5, the initial result of paging is: 2 | 3 | 4 | 5

In the following pages of error:
Warning: implode () [function.implode]: Invalid arguments passed in C: \ Program Files \ xampp \ htdocs \ teste \ search.php on line 511

line 511 corresponds to the code:

$links2 = implode(" | ", $links); 

I would appreciate help from anyone who has a practice in the matter.
Thank you for your kindness in helping ...

Member Avatar for diafol

Is the number of pages static? Or are they determined by the number of records in a DB query result for example?

The number of pages is determined by "bypage, where is integrated into the list of topics per page. In bypage 13 topics is limited. When it's 13 topics, it creates a new page. The number of pages is calculated by the code:

if (! empty ($ _GET [Start]))
{
$ Start = $ _GET [Start];
}
else
{
$ Start = '0 ';
}

$ ByPage = '13 ';

traveling the database:

$ q1 = "select * from class_agents, class_categories, class_subcat, where class_posts class_posts.CategoryID class_categories.CategoryID = and = class_posts.AgentID class_agents.AgentID and class_posts.status! = 'expired' and class_posts.status! = 'notconf' and class_posts . status! = 'notpaid' and class_posts.SubCategoryID class_subcat.subcatid = $ $ MyQuery myOrder limit $ Start, $ ByPage ";

Unfortunately I can not see where the error is.
I would appreciate some help.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.