• 0

Retrieve records and save to array


Question

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

  • 0

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

  • 0

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.

post-314434-12738216116563.png

Is there anyway to limit it?

Link to comment
Share on other sites

This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.