View Single Post
Old 20-11-2007, 15:34   #23 (permalink)
3n1gm4
HEYOOOH!
 
Join Date: Mar 2006
Location: Denton, Tx
Posts: 51
heres my pagination link function which will out put something like

<< < 4 5 6 7 8 9 10 > >>

PHP Code:
function page_this($url$page$number_of_items$total_items$trail_length=3$append=false)
{        
    
$number_of_pages ceil($total_items/$number_of_items);        
    
$seperator = (($append)? "&" "?" ;
    
    
// << < 
    
if ( $page != ){
        
$pagination .= "<a href=\"".$url.$seperator."page=1&show=".$number_of_items."\"><<</a> ";
        
$pagination .= "<a href=\"".$url.$seperator."page=".($page-1)."&show=".$number_of_items."\"><</a> ";
    } else {        
        
$pagination .= "<< ";
        
$pagination .= "< ";
    }
    
    
// previous pages
    
$count $page-$trail_length;
    if ( 
$count <= )
        
$count 1;
    for ( ; 
$count $page$count++) {
        
$pagination .= "<a href=\"".$url.$seperator."page=".$count."&show=".$items_per_page."\">".$count."</a>";        
    }
    
    
// current page
    
$pagination .= $page " ";
    
    
// next pages
    
for ( $count $page$count $number_of_pages && $count $page+$trail_length$count++) {
        
$pagination .= "<a href=\"".$url.$seperator."page=".$count."&show=".$items_per_page."\">".$count."</a>  ";
    }
    
    
// > >>
    
if ( $page $number_of_pages ){
        
$pagination .= "<a href=\"".$url.$seperator."page=".($page+1)."&show=".$number_of_items."\">></a> ";
        
$pagination .= "<a href=\"".$url.$seperator."page=".$number_of_pages."&show=".$number_of_items."\">>></a> ";
    } else {
        
$pagination .= "> ";
        
$pagination .= ">> ";
    }
    return 
$pagination;



and a quick simple example

PHP Code:
$conn mysql_connect('localhost','root','');
mysql_select_db('phpnews');

if(isset(
$_GET['page']) && isset($_GET['show']))
{
    
$show $_GET['show'];
    
$limit = ($_GET['page']-1).",".$show;
    
$page $_GET['page'];
}
else
{
    
$show 10;
    
$limit "0,".$show;
    
$page 1;
}



$sql "SELECT * FROM phpnews_news LIMIT " $limit;
$news_rs mysql_query$sql );

$sql "SELECT COUNT(*) as total FROM phpnews_news";
$total_rs mysql_query$sql );
$total mysql_fetch_array($total_rs);

while ( 
$news mysql_fetch_array($news_rs) )
{
    echo 
$news['titletext'] . "<br><br>";
}

echo 
page_this("pagination.php?hello=2",$page,$show,$total['total'],2,1); 
  Reply With Quote