I have a question about pulling 1000’s of records from a database and efficiently displaying them.
My record set has 5000 records and I want to display it using HTML. It would not be right to make a table with 5000 rows becuase it would take a long time and scrolling would be out of control. So I want to only write the first 50 to the screen and have previous and next buttons to bring up the next or previous set of 50 records. I know this is done all over the net(this site does it with these forums). How do I do this? Are there different options?
if you want 50 recods per page, your should be something like this:
$pageNumber = $_GET['p']-1; // pass the "page number" is the variable "p" to indicate current page
$startAt = $pageNumber*50 // calculate record# to start at, based on page number
$myQuery = "SELECT *";
$myQuery .= "FROM myTable";
$myQuery .= "WHERE ID>'$startAt'";
$myQuery .= "LIMIT 50"; //select only 50 records
Thanks ahmed, that does help. But there is still more.
OK, lets say I want to pull all records with a specific UserID and the UserID is not the primary key(i.e. there are a bunch of records for this user). Your method won’t work. Get what I’m saying?