Jump to content

[SOLVED] Pagination Not Working (doesn't call next page)


tmworking

Recommended Posts

How can I fix my pagination? Links appear, and reload the page, but when I did an echo $page, even though the url is page=2 the echo is showing page 1. Any help would be awesome! Here are the snippets:

 

 

if(!$page) $page = 1;
    $npage = $page - 1;

    if($c){
        $addsql = " AND `cat` = '". $c ."'";
        $addhtml = "&c=". $c;
    }


    $limit1 = $npage * 10;
    $limit2 = $npage + 10;
echo $page;

    $q = "SELECT * FROM `comps` WHERE `accepted` = 'Yes'". $addsql ." ORDER BY `time` DESC LIMIT ". $limit1 .", ". $limit2;

 

then display stuff

 

Then

   $q = "SELECT COUNT(*) FROM `comps` WHERE `accepted` = 'Yes'". $addsql;
    $r = mysql_query($q);
    $num = mysql_fetch_array($r);
    $nbrPages = ceil($num[0] / 10);


    $i = 1;

    $maincontent .= "<br />";

    // Pagination links.
    $nbrPages = $nbrPages;
    $thisPage = "";
    include("pagination.php");
    $maincontent .= $paginationLinks;

 

Below is pagination code

<?php
//$nbrPages = 300;
//$thisPage = "paginationTest.php";
if(strpos($thisPage, "?") === false) {
    $separator = "?";
} else {
    $separator = "&";
}
if($nbrPages > 1) {
    if(isset($_REQUEST['page'])) {
        $currentPage = $_REQUEST['page'];
    } else {
        $currentPage = 1;
    }

    // pagination links
    $links = "";

    // the first links
    // Display the first link separatly or not
    if($currentPage > 5) {
        // display the link separatly
        $links .= "<a href=\"" . $thisPage . $separator . "page=1\">1</a> ... ";
        if($currentPage < 4) {
            $strt = 2;
        } else {
            $strt = $currentPage-4;
        }
        for($i=$strt;$i<$currentPage;$i++) {
            $links .= "<a href=\"" . $thisPage . $separator . "page=" . $i . "\">" . $i . "</a> ";
        }
    } else {
        // display the link with the others
        $links .= "";
        if($currentPage <= 4) {
            $strt = 1;
        } else {
            $strt = $currentPage-4;
        }
        for($i=$strt;$i<$currentPage;$i++) {
            $links .= "<a href=\"" . $thisPage . $separator . "page=" . $i . "\">" . $i . "</a> ";
        }
    }

    // display the current page 'link'
    $links .= "<b class=\"currentPage\">" . $currentPage . "</b> ";

    // Display the last link separatly or not
    if($currentPage < $nbrPages - 4) {
        // display the link separatly
        for($i=$currentPage+1;$i<$currentPage+4;$i++) {
            $links .= "<a href=\"" . $thisPage . $separator . "page=" . $i . "\">" . $i . "</a> ";
        }
        $links .= " ... <a href=\"" . $thisPage . $separator . "page=" . $nbrPages . "\">" . $nbrPages . "</a>";
    } else {
        // display the link with the others
        $links .= "";
        for($i=$currentPage+1;$i<$nbrPages+1;$i++) {
            $links .= "<a href=\"" . $thisPage . $separator . "page=" . $i . "\">" . $i . "</a> ";
        }
    }

    // Next and previous links
    if($currentPage == 1) {
        $nextLink = "<span style=\"color: rgb(170, 170, 170);\">Previous page</span>";
    } else {
        $nextLink = "<a href=\"" . $thisPage . $separator . "page=" . ($currentPage - 1) . "\"><< Previous page</a>";
    }
    if($currentPage == $nbrPages) {
        $previousLink = "<span style=\"color: rgb(170, 170, 170);\">Next page </span>";
    } else {
        $previousLink = "<a href=\"" . $thisPage . $separator . "page=" . ($currentPage + 1) . "\">Next page >></a>";
    }
    $paginationLinks = "<div style=\"font-size:11px;font-family:'Lucida Grande','Lucida Sans Unicode',Verdana,Arial,sans-serif\">
        <div style=\"float:left;\">[ Pages: " . $links . " ]</div>
        <div style=\"float:right;\">
            <sup></sup>
            " . $nextLink . "
            |
            " . $previousLink . "
            <sup></sup>
        </div>
        </div>";
} else {
    $paginationLinks = "";
}

?>

 

Looking forward to learning what I'm doing wrong, thanks!

 

 

 

 

 

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.