Jump to content

Pagination link error


leon

Recommended Posts

Hello;

I am working on pagination and trying to adapt it to my website. But i encountered a problem when displaying to links to the pages.I mean;

(Prev 1 2 3 4 ... Next ) part...

[code]
for($page = 1; $page<= $maxpage; $page++){
        if($page == $currentpage){
            echo($page." ");
        }else{
            echo "<a href=\"$PHP_SELF?page=$page&product_id= (($rowsPerPage * ($page-1)) + 1)\">$page</a> ";
        }
}
[/code]

What I want to do here is that; I am on the first page and wanna go to the second page, When I click on (2) , I want to see (...php?page=2 &product_id=9) page.

I have a variable at the top. ($rowsPerPage=8). But when I hover on (2), the thing I see as a link is: ...php?page=2 &product_id= ((8 * (2-1)) + 1).

You know, if the product_id variable is defined, there is no problem. The correct page comes.
I can provide the whole code if requested
Thanks...

Link to comment
https://forums.phpfreaks.com/topic/7220-pagination-link-error/
Share on other sites

spot the diffrence

good luck.



authors code
[code]
if(!isset($page)) $page = 0;

//mysql_query here to get $page_text

$pagearray=split("[NEXTPAGE]", $page_text);

echo "$page_text";

if($page != 0){
    $prevpage = $page - 1;
    echo "<a href="/link_to_previous_page">Previous Page</a>&nbsp;&nbsp;";
}

if($page < count($pagearray) -1) {
    $nextpage = $page + 1;
    echo "<a href="/link_to_next_page">Next Page</a>";
}

[/code]



your code
[code]


for($page = 1; $page<= $maxpage; $page++){
        if($page == $currentpage){
            echo($page." ");
        }else{
            echo "<a href=\"$PHP_SELF?page=$page&product_id= (($rowsPerPage * ($page-1)) + 1)\">$page</a> ";
        }
}

[/code]
Link to comment
https://forums.phpfreaks.com/topic/7220-pagination-link-error/#findComment-26273
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.