sql >> Databasteknik >  >> RDS >> Mysql

MySQL/PHP - sidnummer paginering Visa endast 10 sidor ibland

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


  1. ClusterControl - Advanced Backup Management - PostgreSQL

  2. Vad är dynamisk SQL?

  3. MySQL-filter på många-till-många

  4. Förhindra mysql casting sträng till int in where-klausul