Mysql
 sql >> Database >  >> RDS >> Mysql

MySQL/PHP - impaginazione del numero di pagina Mostra solo 10 pagine alla volta

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