i want a loop to show my pagination as this.. can anyone help me for this... i only wanted to show 5 buttons at once.

This is my pagination.

OWoxjQO.png

This what i coded for pagination class...

PHP Code:
<?php  
/**
     * @author Chathula Sampath <Schathula@gmail.com>
     * @copyright 2014 || SLTUTS
     * @license http://www.php.net/license/3_01.txt PHP License 3.01
     * @link http://sltuts.com || http://fb.com/c.sampathperera || http://twitter.com/ChathulaC
*/

/*  USAGE EXAMPLE */

/*

$nums = $pagination->Paginate("SELECT id,text FROM test", 2, $_GET['page']);
$result = $pagination->FetchResult();
echo "</ul>";
foreach ($result as $r) {
    echo "<li>" . $r->text ."</li>";
}
echo "</ul><br />";

echo $nums;

*/

class Pagination {

    protected 
$connection;
    protected 
$data = array();
    protected 
$perPage;
    protected 
$offset;
    protected 
$pageName;

    public function 
__construct($conn) {
        
$this->connection $conn;
    }

    public function 
Paginate($query$perPage, &$param) {


        
$stmt DB::query($query""$this->connection);
        
$totalPages $stmt->rowCount();
        
$stmt = (array) $stmt;
        
        if (isset(
$param)) {
            
$currentPage = (int) $param;

            if (empty(
$param) || $currentPage $totalPages) {
                
$currentPage 1;
            }

        } else {
            
$currentPage 1;
        }

        
$pageCounts ceil($totalPages $perPage);
        
$param1 = ($currentPage 1) * $perPage;
        
$this->data array_slice($stmt$param1$perPage);

        for (
$x 1$x <= $pageCounts$x++) {
            
$numbers[] = $x;
        }


        
$this->query $query;
        
$this->perPage $perPage;
        
$this->offset $param1;
        
        
$output '<div class="pagination">';

        
$output .= "<span class='pagText'>Page <b>$currentPage</b> Of <b>$pageCounts</b></span>";

        if (
$currentPage != 1) {
            
$firstLink "<a class='pagLink first' href='?page=1'>First</a>";
            
$output .= $firstLink;

            
$previousId $currentPage 1
            
$previousLink "<a class='pagLink np' href='?page=$previousId'>Previous</a>";
            
$output .= $previousLink;
        }

        foreach (
$numbers as $num) {
            if (
$num == $currentPage) {
                
$output .= "<a class='pagLink active' href='?page=$num'>$num</a>";
            } else {
                
$output .= "<a class='pagLink' href='?page=$num'>$num</a>";
            }
            
        }

        if (
$currentPage != $pageCounts) {
            
$nextId $currentPage 1;
            
$nextLink "<a class='pagLink np' href='?page=$nextId'>Next</a>";
            
$output .= $nextLink;

            
$lastLink "<a class='pagLink last' href='?page=$pageCounts'>Last</a>";
            
$output .= $lastLink;
        }

        
$output .= "</div>";

        return 
$output;

    }

    public function 
FetchResult() {
        
$offset $this->offset;
        
$perPage $this->perPage;
        
$query $this->query " LIMIT $offset$perPage";
        
$result DB::query($query""$this->connection"FETCH");
        return 
$result;
    }

    public function 
callAll() {



    }


}


?>
NOTE: DB::query method is class i coded for run queries with database!


Just think like this.I have 100 pages.(in picture there have only 5 pages -> Dont think about Page 5 Of 10 it is just a sample html, not a php one).in my pagination if there have 100 pages all of the page numbers is showed in the pagination, now i want to only show 5 at once. i want a code to do it. a loop or something else.

or tell me how to do like this.(i want to do 2nd one).


pagination.jpg


Some Description about my pagination class.

i get the total number of pages and put it into a array through the for loop.

PHP Code:
for ($x 1$x <= $pageCounts$x++) {
            
$numbers[] = $x;
        } 


then i do some conditions and loop the $numbers array!


PHP Code:
    $output '<div class="pagination">';

        
$output .= "<span class='pagText'>Page <b>$currentPage</b> Of <b>$pageCounts</b></span>";

        if (
$currentPage != 1) {
            
$firstLink "<a class='pagLink first' href='?page=1'>First</a>";
            
$output .= $firstLink;

            
$previousId $currentPage 1
            
$previousLink "<a class='pagLink np' href='?page=$previousId'>Previous</a>";
            
$output .= $previousLink;
        }

        foreach (
$numbers as $num) {
            if (
$num == $currentPage) {
                
$output .= "<a class='pagLink active' href='?page=$num'>$num</a>";
            } else {
                
$output .= "<a class='pagLink' href='?page=$num'>$num</a>";
            }
            
        }

        if (
$currentPage != $pageCounts) {
            
$nextId $currentPage 1;
            
$nextLink "<a class='pagLink np' href='?page=$nextId'>Next</a>";
            
$output .= $nextLink;

            
$lastLink "<a class='pagLink last' href='?page=$pageCounts'>Last</a>";
            
$output .= $lastLink;
        }

        
$output .= "</div>"