Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
Pagination .... limit
Old 05-18-2012, 08:28 AM Pagination .... limit
Junior Talker

Posts: 1
Trades: 0
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 basic, and work.

PHP Code:

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);// number of pages
         
for($i 0$i <= ($pages); $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>";
            
$ListingTable .= "</table><br><br>\n";
         }
         else  
// rows <= bypage (no navbar required)
         
{
          
$ListingTable .= "<br><br>\n";
         }
}  
// lrows >0 
Now, I managed to get this code to limit the number of pages, but unfortunately has an error, because the pages are not correct.
I think it is in the code. As an example of 10 pages, the first page does not appear, and when I click on page 2, the result of this page no longer appears the page 3 | 4 | 5 ... , but the page 7, and no further.

Is there some simple code that can integrate this. Or does missing some function in the code?
The code is:

PHP Code:
$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 5;
 
$lowAllow = (int)($Start - ($pagesLimit 2));  
$Start = ($lowAllow <= 0) ? $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 = array();
                  
$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 ";   
               }
            }
            
var_dump$links );
            
$links2 implode(" | "$links);
      
            
$ListingTable .= $links2;
            
$ListingTable .= "| </td></tr>";
            
$ListingTable .= "</table><br><br>\n";
         }
         else  
// rows <= bypage (no navbar required)
         
{
          
$ListingTable .= "<br><br>\n";
         } 
Someone can help me, please!

Thanks for attention

MM
Netpt is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 05-19-2012, 05:59 AM Re: Pagination .... limit
chrishirst's Avatar
Defies a Status

Posts: 43,949
Name: Chris Hirst
Location: Blackpool. UK
Trades: 0
http://php.about.com/od/phpwithmysql...pagination.htm
__________________
Chris. ->>
Please login or register to view this content. Registration is FREE
<<-

A foolish consistency is the hobgoblin of little minds
Thought for today:- Is SEO the only industry where all the cowboys are Indians?
chrishirst is offline
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Reply     « Reply to Pagination .... limit
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.12874 seconds with 11 queries