leon Posted April 12, 2006 Share Posted April 12, 2006 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... Quote Link to comment https://forums.phpfreaks.com/topic/7220-pagination-link-error/ Share on other sites More sharing options...
redarrow Posted April 12, 2006 Share Posted April 12, 2006 spot the diffrencegood 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> ";}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] Quote Link to comment https://forums.phpfreaks.com/topic/7220-pagination-link-error/#findComment-26273 Share on other sites More sharing options...
jworisek Posted April 12, 2006 Share Posted April 12, 2006 to use your existing code you should be able to just do this:[code]echo "<a href=\"$PHP_SELF?page=$page&product_id=".(($rowsPerPage * ($page-1)) + 1)."\">$page</a> "; [/code]so that the math operations are done [u]outside[/u] of the string. Quote Link to comment https://forums.phpfreaks.com/topic/7220-pagination-link-error/#findComment-26276 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.