Mysql
 sql >> Base de Dados >  >> RDS >> Mysql

MySQL/PHP - paginação do número da página Mostra apenas 10 páginas às vezes

function getPageRange($current, $max, $total_pages = 10) {
    $desired_pages = $max < $total_pages ? $max : $total_pages;
    $middle = ceil($desired_pages/2);
    if ($current <= $middle){
        return [1, $desired_pages];
    }
    if ($current > $middle && $current <= ($max - $middle)) {
        return [
            $current - $middle,
            $current + $middle
        ];
    }
    if ($current <= $max ) {
        return [
            $current - ($desired_pages - 1),
            $max
        ];
    }

}
list($min,$max) = getPageRange($sidenr, $sideantal);


foreach (range($min, $max) as $number) {
    echo "<li><a href=\"test.php?page=".$number."\" >". $number. "</a></li>";
}