newbtophp Posted February 24, 2010 Share Posted February 24, 2010 Im having a bit of trouble on calulating the number of showing search results, if I have 20 search results per page, and page number was 1, it should echo 1-20, if the page number was 2 it would echo 21 - 40, if the page number was 3 it would echo 41 - 60... and soo on. My code; <?php $totalresults = 348; $perpage = 20; $page = 1; ?> :-\ Quote Link to comment https://forums.phpfreaks.com/topic/193250-how-to-determine-showing/ Share on other sites More sharing options...
premiso Posted February 24, 2010 Share Posted February 24, 2010 $showing = "Currently Showing {$page} - " . ($perpage * $page) . " of " . $totalresults; Quote Link to comment https://forums.phpfreaks.com/topic/193250-how-to-determine-showing/#findComment-1017544 Share on other sites More sharing options...
aeroswat Posted February 24, 2010 Share Posted February 24, 2010 Im having a bit of trouble on calulating the number of showing search results, if I have 20 search results per page, and page number was 1, it should echo 1-20, if the page number was 3 it would echo 41 - 60. My code; <?php $totalresults = 348; $perpage = 20; $page = 1; ?> :-\ Use the LIMIT keyword in your query like such. $qry = "SELECT * FROM tbl LIMIT " . (($page-1) * 20) . ", " . (($page*20)-1); Quote Link to comment https://forums.phpfreaks.com/topic/193250-how-to-determine-showing/#findComment-1017546 Share on other sites More sharing options...
MatthewJ Posted February 24, 2010 Share Posted February 24, 2010 $qry = "SELECT * FROM tbl LIMIT " . (($page-1) * 20) . ", " . (($page*20)-1); First query would be SELECT * FROM tbl LIMIT 0, 19 or select everything from table, start at record 0 and get 19 records So let's say were then on page two... The query would then be SELECT * FROM tbl LIMIT 20, 39 The two arguments to limit are record to start counting from, and number of records to return, not which records to start and end with. So the second parameter should always be 20 Quote Link to comment https://forums.phpfreaks.com/topic/193250-how-to-determine-showing/#findComment-1017550 Share on other sites More sharing options...
aeroswat Posted February 24, 2010 Share Posted February 24, 2010 $qry = "SELECT * FROM tbl LIMIT " . (($page-1) * 20) . ", " . (($page*20)-1); First query would be SELECT * FROM tbl LIMIT 0, 19 or select everything from table, start at record 0 and get 19 records So let's say were then on page two... The query would then be SELECT * FROM tbl LIMIT 20, 39 The two arguments to limit are record to start counting from, and number of records to return, not which records to start and end with. So the second parameter should always be 20 My bad I wrote that wrong. Thanks for correcting Quote Link to comment https://forums.phpfreaks.com/topic/193250-how-to-determine-showing/#findComment-1017555 Share on other sites More sharing options...
newbtophp Posted February 25, 2010 Author Share Posted February 25, 2010 Thanks both of you Quote Link to comment https://forums.phpfreaks.com/topic/193250-how-to-determine-showing/#findComment-1018126 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.