Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

pagination php only 10 items

I have a problem with pagination, how to display only 10 items? can do something like this in google - number increased by +5?

enter image description here

<?php
// Make the links to other pages, if necessary.
if ($pages > 1) {

    echo '<br /><p>';
    $current_page = ($start/$display) + 1;

    // If it's not the first page, make a Previous button:
    if ($current_page != 1) {
        echo '<a href="list_photos_4.php?s=' . ($start - $display) . '&p=' . $pages . '&sort=' . $sort . '">Previous</a> ';
    }

    // Make all the numbered pages:
    for ($i = 1; $i <= $pages; $i++) {
        if ($i != $current_page) {
            echo '<a href="list_photos_4.php?s=' . (($display * ($i - 1))) . '&p=' . $pages . '&sort=' . $sort . '">' . $i . '</a> ';
        } else {
            echo $i . ' ';
        }
    } // End of FOR loop.

    // If it's not the last page, make a Next button:
    if ($current_page != $pages) {
        echo '<a href="list_photos_4.php?s=' . ($start + $display) . '&p=' . $pages . '&sort=' . $sort . '">Next</a>';
    }

    echo '</p>'; // Close the paragraph.

} // End of links section.
?>
like image 727
Mantykora 7 Avatar asked Jan 31 '26 01:01

Mantykora 7


1 Answers

Try to change section (Make all the numbered pages) to this:

// Make all the numbered pages:
    for ($i = 1; $i <= $pages; $i++) {    
        if ($i != $current_page) {
            $distance = $current_page - $i;
            if (abs($distance) < 5){
                echo '<a href="list_photos_4.php?s=' . (($display * ($i - 1))) . '&p=' . $pages . '&sort=' . $sort . '">' . $i . '</a> ';
            } 
        } else {
            echo $i . ' ';
        }
    } // End of FOR loop

I hope this work fine for You.

like image 97
Adam Avatar answered Feb 01 '26 16:02

Adam