PHP & MySQL Pagination Update Help

Posted by TaG on Stack Overflow See other posts from Stack Overflow or by TaG
Published on 2010-05-10T23:30:43Z Indexed on 2010/05/10 23:34 UTC
Read the original article Hit count: 175

Filed under:
|

Its been a while since I updated my pagination on my web page and I'm trying to add First and Last Links to my pagination as well as the ... when the search results are to long. For example I'm trying to achieve the following in the example below. Can some one help me fix my code so I can update my site. Thanks

Previous First 1 2 3 4 5 6 7 ... 199 200 Last Next

I currently have the following displayed using my code.

Previous 1 2 3 4 5 6 7 Next

Here is the part of my pagination code that displays the links.

if ($pages > 1) {

    echo '<br /><p>';

    $current_page = ($start/$display) + 1;

    if ($current_page != 1) {
        echo '<a href="index.php?s=' . ($start - $display) . '&p=' . $pages . '">Previous</a> ';
    }

    for ($i = 1; $i <= $pages; $i++) {
        if ($i != $current_page) {
            echo '<a href="index.php?s=' . (($display * ($i - 1))) . '&p=' . $pages . '">' . $i . '</a> ';
        } else {
            echo '<span>' . $i . '</span> ';
        }
    } 

    if ($current_page != $pages) {
        echo '<a href="index.php?s=' . ($start + $display) . '&p=' . $pages . '">Next</a>';
    }

    echo '</p>';

}

© Stack Overflow or respective owner

Related posts about php

Related posts about mysql