Jump to content


Photo

Pagination link error


  • Please log in to reply
2 replies to this topic

#1 leon

leon
  • New Members
  • Pip
  • Newbie
  • 9 posts

Posted 12 April 2006 - 03:52 PM

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

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> "; 
        }
 }

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



#2 redarrow

redarrow
  • Members
  • PipPipPip
  • Advanced Member
  • 7,308 posts
  • Locationlondon

Posted 12 April 2006 - 03:58 PM

spot the diffrence

good luck.



authors 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>";
}




your 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> "; 
        }
}


Wish i new all about php DAM i will have to learn
((EMAIL CODE THAT WORKS))
http://simpleforum.ath.cx/mail2.inc
((PAYPAL INTEGRATION THAT WORKS))
http://simpleforum.a...aypal1_info.inc

#3 jworisek

jworisek
  • Members
  • PipPipPip
  • Advanced Member
  • 112 posts

Posted 12 April 2006 - 04:03 PM

to use your existing code you should be able to just do this:

echo "<a href=\"$PHP_SELF?page=$page&product_id=".(($rowsPerPage * ($page-1)) + 1)."\">$page</a> "; 

so that the math operations are done outside of the string.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users