Mysql
 sql >> Base de données >  >> RDS >> Mysql

MySQL/PHP - pagination des numéros de page N'affiche que 10 pages à la fois

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>";
}