Banner

Sponsor

Login


Welcome Back!
Guest
Guest

Register

Lost your password?

96 users online



Page script

Page script

Currently viewing this thread: 1 (0 members and 1 guests)


ChadWick

ChadWick

Music, sex, computers
Status: Offline!

Page script

Im using the standard page script in php:

PHP:

<?php
    
    
require("db.php");

        
db_connect();
        

    
$max_results 2;

if(!isset(
$_GET['page'])){
    
$page 1;
} else {
    
$page $_GET['page'];
}

$from = (($page $max_results) - $max_results); 

    
        
$sql mysql_query("SELECT id, uid, title, category_main, category_sub, description FROM `tutorials` LIMIT $from, $max_results") or die("MySQL Error"); 

while(
$row mysql_fetch_array($sql))
{
echo( 
"<b>$row[title]</b><br>" );
echo( 
"    submitted by $row[uid] in $row[category_main] / $row[category_sub]<br>" );
echo( 
"<i>$row[description]</i><br><br>" );

}

$total_results mysql_result(mysql_query("select count(*) as Num FROM tutorials"),0);

$total_pages ceil($total_results $max_results);

 if((
$total_pages) < 2){ echo "..."; }
 else{

echo 
"Page <b>$page</b> out of <b>$total_pages</b><br />";

if(
$page 1){
    
$prev = ($page 1);
    echo 
"<a href=\"".$_SERVER['PHP_SELF']."?page=$prev\"><<Previous</a> ";
}

for(
$i 1$i <= $total_pages$i++){
    if((
$page) == $i){
        echo 
"$i ";
        } else {
            echo 
"<a href=\"".$_SERVER['PHP_SELF']."?page=$i\">$i</a> ";
    }
}

if(
$page $total_pages){
    
$next = ($page 1);
    echo 
"<a href=\"".$_SERVER['PHP_SELF']."?page=$next\">Next>></a>";
}

}
            

        
db_disconnect();
    
    
?>

blah blah blah but what im trying to do the effect where it will display 5 page numbers at a time only the dot dot dot to the last and first two pages... example

http://bin1.myphotoupload.com/pages.gif

it basicly displays the page your on then 2 pages ahead... 2 pages behind... the first 2 pages and last two pages....

Thanks

___________________

xxYY

BigToach

BigToach

Neversidian
Status: Offline!

Where did I come from?

PHP:

<?php

function pageinate($total_results$page=1$per_page=10)
{
        
$offset 2// # of numbers next to the current page ex: 1-2...4-5,6,7-8...10-11, in this example it is 45 and 78 (6 is current page)
        
$first_last 2// # of digits at beginning and start, above example is 12 and 1011

        
$pages ceil($total_results $per_page);
        
$page max(min($page$pages), 1);

        
$links = array();

        if(
$page != 1)
        {
                
$links['previous'] = $page 1;
        }

        for(
$i=1;$i<min($first_last 1$page);$i++)
        {
                
$links['first'][] = $i;
        }

        if(
$page > ($offset $first_last 1))
        {
                
$links['before_dots'] = '...';
        }

        for(
$i=max(($page $offset), ($first_last 1));$i<$page;$i++)
        {
                
$links['before'][] = $i;
        }

        
$links['page'] = $page;

        for(
$i=($page 1);$i<=min(($page $offset), ($pages $first_last));$i++)
        {
                
$links['after'][] = $i;
        }

        if(
$page < ($pages $offset $first_last 1))
        {
                
$links['after_dots'] = '...';
        }

        for(
$i=max(($pages $first_last 1), ($page 1));$i<=$pages;$i++)
        {
                
$links['last'][] = $i;
        }

        if(
$page != $pages)
        {
                
$links['next'] = $page 1;
        }

        return 
$links;
}

// So $results is the total # of results from the DB
// $page is the current page that you are on
// $per_page is the number of results per page

$pageinate pageinate(412710);

?>


then build your links off of that

Enjoy and Hello to everyone

___________________

Neverside Development Director
PHP Snippets
BigToach.com - IT WORKS, TOACHY!

glazz

glazz

Neverside Newbie
Status: Offline!

Using BigToach function here it is what you need, and helped me too, thanks BigToach

PHP:

<style type="text/css">
<!--
body,td,th {
    font-family: Verdana, Arial, Helvetica, sans-serif;
    font-size: 9px;
    color: #666666;
}
body {
    background-color: #FFFFFF;
    margin-left: 10px;
    margin-top: 10px;
    margin-right: 10px;
    margin-bottom: 10px;
}

.pagelink,
.pagelinklast,
.pagecurrent{
    background: #f2f2f2;
    border: 1px solid #d4d4d4;
    padding: 3px 3px 3px 3px;
}
.pagecurrent{
    background: #f2f2f2;
    font-weight:bold;
    color: #003366;
}
.pagelink a:active,
.pagelink a:visited,
.pagelink a:link,
.pagecurrent a:active,
.pagecurrent a:visited,
.pagecurrent a:link{
    text-decoration: none;color: #003366;
}
-->
</style>
<?php
function pageinate($total_results$page=1$per_page=10)
{
    
$offset 2// # of numbers next to the current page ex: 1-2...4-5,6,7-8...10-11, in this example it is 45 and 78 (6 is current page)
    
$first_last 2// # of digits at beginning and start, above example is 12 and 1011

    
$pages ceil($total_results $per_page);
    
$page max(min($page$pages), 1);

    
$links = array();

    if(
$page != 1)
    {
        
$links[] = '<span class="pagelink"><a href="?pag='.($page-1).'">< Previous</a></span>';
    }
        
    for(
$i=1;$i<min($first_last 1$page);$i++)
    {
        
$links[] = '<span class="pagelink"><a href="?pag='.$i.'">'.$i.'</a></span>';
    }
        
    if(
$page > ($offset $first_last 1))
    {
        
$links[] = '...';
    }

    for(
$i=max(($page $offset), ($first_last 1));$i<$page;$i++)
    {
        
$links[] = '<span class="pagelink"><a href="?pag='.$i.'">'.$i.'</a></span>';
    }

    
$links[] = '<span class="pagecurrent">'.$page.'</span>';
    
    for(
$i=($page 1);$i<=min(($page $offset), ($pages $first_last));$i++)
    {
        
$links[] = '<span class="pagelink"><a href="?pag='.$i.'">'.$i.'</a></span>';
    }
    
    if(
$page < ($pages $offset $first_last 1))
    {
        
$links[] = '...';
    }
    
    for(
$i=max(($pages $first_last 1), ($page 1));$i<=$pages;$i++)
    {
        
$links[] = '<span class="pagelink"><a href="?pag='.$i.'">'.$i.'</a></span>';
    }
    
    if(
$page != $pages)
    {
        
$links[] = '<span class="pagelink"><a href="?pag='.($page+1).'">Next ></a></span>';
    }

    return 
implode('&nbsp;'$links);
}

// So $results is the total # of results from the DB
// $page is the current page that you are on
// $per_page is the number of results per page

$page $_GET['pag'];

$pageinate pageinate(412$page15);

echo 
$pageinate;
?>

Quick Jump:

Main Navigation


Site & Graphic Design by Aeon Tan
Developed by Jeremie Pelletier & Scott Roach


NeverAPI generated this page in 0.0129 seconds.