w3hello.com logo
Home PHP C# C++ Android Java Javascript Python IOS SQL HTML videos Categories
How to limit the number of pagination pages - PHP

you can try displaying it as a dropdown between the 'next' and 'prev' button if you want.. it would be easier to display all the page numbers..

or you can first get the value of current page, add 5 and store it as '$add' and minus 5 and store it as '$minus' then insert this in the page buttons:

<input type="submit" value="<?php echo $page_num;?>"
<?php if($pagenum > $add || $pagenum < $minus){ echo

it will hide the buttons that are more than 5 and less than 5 the current page

replace yor 'for' with this:

    $get_add = $params["set"] + 5;
    $get_minus = $params["set"] - 5;
    for($i = 1; $i <= $pages; $i++) {
        $class = $set == $i ? "active" : "";
        <li class="<?php echo $class; ?>" <?php if($i >
$get_add || $i < $get_minus){ echo
"style='display:none;position:absolute'";?>><a href="?<?php
echo $query; ?>&set=<?php echo $i.""; ?>"><?php echo $i;

© Copyright 2018 w3hello.com Publishing Limited. All rights reserved.