在分页中显示...

I have some pagination issue. My pagination work fine. But I want to display started 3 page after that I want to display (....) and at last point I want to display my last page. Here is my code:

<?php
$videocount= 1000;
$page = (!isset($_GET['page']))? 1 : $_GET['page'];
$prev = ($page - 1);
$next = ($page + 1);

/* Max results per page */
$max_results = 50;

/* Calculate the offset */
$from = (($page * $max_results) - $max_results);
$last = $from + $max_results;

/* Query the Api for total results.*/
//$total=107;
$total_results = $videocount;
$total_pages = ceil($total_results / $max_results);
if($page==$total_pages ){
    $last=$total_results ;
}else{
    $last=$last;    
}

$pagination = '';
/* Create a PREV link if there is one */
if($page > 1) {
    $pagination.= '<li> <a href="?&page='.$prev.'"> <span class="prevBtn"><i class="fa fa-caret-left"></i> Previous</span> </a></li>';
}
/* Loop through the total pages */
//for($i = 1; $i <= $total_pages; $i++) before meeting code
for($i = 1; $i <=  $total_pages; $i++) {
    if(($page) == $i) {
        //$pagination .= $i;
        $pagination .= '<li> <a href="#"> <span>'.$i.' </span> </a></li>'; //implement active class here
    } else {
        $pagination .= '<li> <a href="?page='.$i.'"> <span> '.$i.' </span> </a></li>';
    }
}

if($page < $total_pages) {
    $pagination.= '<li> <a href="?page='.$next.'"> <span class="nextBtn"> Next <i class="fa fa-caret-right"></i> </span> </a></li>';
}
?>

Thanks,

I have added a If...Else statement inside the loop in your code. This might help you

<?php  
$videocount= 1000;
$page = (!isset($_GET['page']))? 1 : $_GET['page'];
$prev = ($page - 1);
$next = ($page + 1);
/* Max results per page */
$max_results = 50;
/* Calculate the offset */
$from = (($page * $max_results) - $max_results);
$last=$from + $max_results;
/* Query the Api for total results.*/
//$total=107;
$total_results = $videocount;
$total_pages = ceil($total_results / $max_results);
if($page==$total_pages ) {
    $last=$total_results ;
} else {
    $last=$last;    
}
$pagination = '';

/* Create a PREV link if there is one */
if($page > 1) {
    $pagination.= '<li> <a href="?&page='.$prev.'"> <span class="prevBtn"><i class="fa fa-caret-left"></i> Previous</span> </a></li>';
}

/* Loop through the total pages */
//for($i = 1; $i <= $total_pages; $i++) before meeting code
for($i = 1; $i <=  $total_pages; $i++) {
    if(($page) == $i) {
        //$pagination .= $i;
        $pagination .= '<li> <a href="#"> <span>'.$i.' </span> </a></li>';      //implement active class here
    } else {
        //Display first 3 pages
        if($i<=3)
            $pagination .= '<li> <a href="?page='.$i.'"> <span> '.$i.' </span> </a></li>';
        //Display last 3 pages
        else if($total_pages-$i<3)
            $pagination .= '<li> <a href="?page='.$i.'"> <span> '.$i.' </span> </a></li>';
        else {
            if($total_pages-$i<=6)
                $pagination .= '<li> <a href="?page='.$i.'"> <span> . </span> </a></li>';
        }
    }
}
if($page < $total_pages) {
    $pagination.= '<li> <a href="?page='.$next.'"> <span class="nextBtn"> Next <i class="fa fa-caret-right"></i> </span> </a></li>';
}
echo $pagination;
?>