adamjblakey Posted August 13, 2007 Share Posted August 13, 2007 I have implemented this but i seem to be having problems. When i go to the next page it changes this statement: select * from sellproperty WHERE buylet='Buy' limit -10, 10 to this when i click on e.g. page 2. select * from sellproperty WHERE buylet='Buy' limit 0, 10 but it does not like this statement and throws an error because it should be 10, 10 not -10, 10 i assume . Now this is not the only problem i am having. I would have thought that when i go through the pages it would go up like so 10, 10 - 20, 10 - 30, 10 etc but page 1, 2 and 3 all say -10, 10. My first question is how do i remove the - and also why is my code not going up in 10's? Here is the code: class Pager { function getPagerData($numHits, $limit, $page) { $numHits = (int) $numHits; $limit = max((int) $limit, 1); $page = (int) $page; $numPages = ceil($numHits / $limit); $page = max($page, 1); $page = min($page, $numPages); $offset = ($page - 1) * $limit; $ret = new stdClass; $ret->offset = $offset; $ret->limit = $limit; $ret->numPages = $numPages; $ret->page = $page; return $ret; } } // get the pager input values $page = $_GET['page']; $limit = 10; $result = mysql_query("select count(*) FROM sellproperty WHERE $stored"); $total = mysql_result($result, 0, 0); // work out the pager values $pager = Pager::getPagerData($total, $limit, $page); $offset = $pager->offset; $limit = $pager->limit; $page = $pager->page; // output paging system (could also do it before we output the page content) if ($page == 1) // this is the first page - there is no previous page echo "Previous"; else // not the first page, link to the previous page echo "<a href=\"property-search.php?set=$setquery&querypage=" . ($page - 1) . "\">Previous</a>"; for ($i = 1; $i <= $pager->numPages; $i++) { echo " | "; if ($i == $pager->page) echo "Page $i"; else echo "<a href=\"property-search.php?set=$setquery&page=$i\">Page $i</a>"; } if ($page == $pager->numPages) // this is the last page - there is no next page echo " | Next"; else // not the last page, link to the next page echo "<a href=\"property-search.php?set=$setquery&page=" . ($page + 1) . "\"> | Next</a>"; Quote Link to comment https://forums.phpfreaks.com/topic/64633-php-pagination/ Share on other sites More sharing options...
sasa Posted August 13, 2007 Share Posted August 13, 2007 where you create your SQL string Quote Link to comment https://forums.phpfreaks.com/topic/64633-php-pagination/#findComment-322441 Share on other sites More sharing options...
PhaZZed Posted August 13, 2007 Share Posted August 13, 2007 http://www.phpfreaks.com/forums/index.php/topic,154566.0.html Looks like they solved things there Quote Link to comment https://forums.phpfreaks.com/topic/64633-php-pagination/#findComment-322446 Share on other sites More sharing options...
adamjblakey Posted August 13, 2007 Author Share Posted August 13, 2007 That is a different problem they solved. It looks like the problem is here: $offset = ($page - 1) * $limit; Say i click on page 1 i get -10, 10 but i should be getting 10, 10 And if i click on page 2 i should get 20, 10 not -10, 10 like i am doing at the moment. Any ideas? Quote Link to comment https://forums.phpfreaks.com/topic/64633-php-pagination/#findComment-322539 Share on other sites More sharing options...
thefortrees Posted August 13, 2007 Share Posted August 13, 2007 maybe you are calling the function with $page == 0? Quote Link to comment https://forums.phpfreaks.com/topic/64633-php-pagination/#findComment-322556 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.