Jump to content

Google Like Pagination


unemployment

Recommended Posts

$count="SELECT COUNT(*) FROM yourtable ORDER BY id DESC";
$sql="SELECT * FROM `yourtable` ORDER BY id DESC";

// Perform a query getting back a MySQLResult object
$res = $db->query($count);
$result = $db->query($sql);

//get the number of rows in datatbase
$getresult = $result->size();

$numrows = $res->fetchrow();

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

$entries_per_page = 1;   

$total_pages = ceil($numrows[0]/$entries_per_page); 
$offset = (($page * $entries_per_page) - $entries_per_page); 

 

and to call the function to display the links

pagination($$total_pages,$page);

This is the function to create the paging

 

function pagination($total_pages,$page){ 

    // Global variable passed between the pages
    global $webpage; 

    // Maximum number of links per page.  If exceeded, google style pagination is generated
    $max_links = 6; 
    $h=1; 
    if($page>$max_links){ 
        $h=(($h+$page)-$max_links); 
    } 
    if($page>=1){ 
        $max_links = $max_links+($page-1); 
    } 
    if($max_links>$total_pages){ 
        $max_links=$total_pages+1; 
    } 
    echo '<div class="page_numbers"> 
      <ul>'; 
    if($page>"1"){ 
        echo '<li class="current"><a href="/'.$webpage.'/1">First</a></li> 
              <li class="current"><a href="/'.$webpage.'/'.($page-1).'">Prev</a></li> '; 
    } 
     
    if($total_pages!=1){ 
        for ($i=$h;$i<$max_links;$i++){ 
            if($i==$page){ 
                echo '<li><a class="current">'.$i.'</a></li>'; 
            } 
            else{ 
                echo '<li><a href="/'.$webpage.'/'.$i.'">'.$i.'</a> </li>'; 
            } 
        } 
    } 
     
    if(($page >="1")&&($page!=$total_pages)){ 
        echo '<li class="current"><a href="/'.$webpage.'/'.($page+1).'">Next</a></li> 
              <li class="current"><a href="/'.$webpage.'/'.$total_pages.'">Last</a></li>'; 
    } 
     
    echo '</ul> </div>'; 
}

 

the css

 

.page_numbers {
width:100%;
background:#fff9f0;
overflow:hidden;
position:relative;
padding:50px 0;
}
.page_numbers ul {
clear:left;
float:left;
list-style:none;
margin:0;
padding:0;
position:relative;
left:50%;
text-align:center;
}
.page_numbers ul li {
display:block;
float:left;
list-style:none;
margin:1px;
padding:0;
position:relative;
right:50%;
background: #a8a189; 
width:25px; 

}
.page_numbers ul li a {
display:block;
background: #fff; 
border: 1px solid #a8a189; 
padding:3px 6px; 
text-decoration: none; 
color: #7a7564; 
font:bold 11px arial, verdana,sans-serif;
}

 

any probs give us a shout

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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