RoomKid Posted May 14, 2010 Share Posted May 14, 2010 Right now I'm retrieving all my records and saving it to an array. But what happens if I have 2000 records to fetch? Doesn't this slow down the page? Thanks:D Link to comment Share on other sites More sharing options...
0 nvme Posted May 14, 2010 Share Posted May 14, 2010 use limit (mysql) or top (mssql) to reduce your record sets to only the number of records you need for the page. also select just the fields you need for the query as apposed to doing a select * and returning everything. both of these will return the 10 records containing first and last name in ascending order. mysql limit: SELECT FirstName, LastName FROM Person ORDER BY LastName ASC LIMIT 10 mssql top: SELECT TOP 10 FirstName, LastName FROM Person ORDER BY LastName ASC Link to comment Share on other sites More sharing options...
0 RoomKid Posted May 14, 2010 Author Share Posted May 14, 2010 use limit (mysql) or top (mssql) to reduce your record sets to only the number of records you need for the page. also select just the fields you need for the query as apposed to doing a select * and returning everything. both of these will return the 10 records containing first and last name in ascending order. mysql limit: SELECT FirstName, LastName FROM Person ORDER BY LastName ASC LIMIT 10 mssql top: SELECT TOP 10 FirstName, LastName FROM Person ORDER BY LastName ASC I tried that but the pagination got me stuck here: for($page = 1; $page <= $maxPage; $page++) { if($page == $pageNum) { $nav .= " $page "; } else { $nav .= " <a href=\"$self?page=$page\">$page</a>"; } } Now if I have 2000 records and I limit it to 5, it will show 400 pages(in numbers). It wouldn't look good. Is there anyway to limit it? Link to comment Share on other sites More sharing options...
0 nvme Posted May 14, 2010 Share Posted May 14, 2010 ah, so you want a count of the rows. SELECT COUNT(1) AS TotalPersons FROM Person that will return the number of records in the Person table Link to comment Share on other sites More sharing options...
Question
RoomKid
Right now I'm retrieving all my records and saving it to an array. But what happens if I have 2000 records to fetch? Doesn't this slow down the page?
Thanks:D
Link to comment
Share on other sites
3 answers to this question
Recommended Posts