hey guys,
I'm doing some brain storming and getting ideas to come up with a solution.
I have a list of ....data... that is displayed 10 per page with the LIMIT clause.
Simply put: My requirement is to jump to the page a particular record is on from a search criteria.
For example, if I'm going to get to record "John", I want to go to the page that John falls on if the list was sorted by primary/id, so that the user can still click previous page and next page as if they manually went to that page where John is.
My Solution, (in Pseudocode, these are not live queries)
//pretend there's only one john and this returns one record
** SELECT id FROM table WHERE name = "john"
$selectedID = id
//to get which record john falls on:
** SELECT COUNT(id) FROM table WHERE id < $selectedID ...sort criteria here..;
//Let's say that John is at number 53 when sorted by ID ASC, this means that he'll be on page 50-60 if 10 items per page.
50 = round(53) // round to 10ths.
$num = 50 - 10; // LIMIT starts at page 0, so minus one page (10)
then put this value in the limit
**SELECT my,fields,here FROM table LIMIT $num,10;
This is a common problem and I'm sure there are other solutions other than what I have above.
My Question:
Any easier way to do this? Other creative solutions or ideas (i'm not expecting much) or random babble you can contribute is appreciated.
Ciao!
Dan
I'm doing some brain storming and getting ideas to come up with a solution.
I have a list of ....data... that is displayed 10 per page with the LIMIT clause.
Simply put: My requirement is to jump to the page a particular record is on from a search criteria.
For example, if I'm going to get to record "John", I want to go to the page that John falls on if the list was sorted by primary/id, so that the user can still click previous page and next page as if they manually went to that page where John is.
My Solution, (in Pseudocode, these are not live queries)
//pretend there's only one john and this returns one record
** SELECT id FROM table WHERE name = "john"
$selectedID = id
//to get which record john falls on:
** SELECT COUNT(id) FROM table WHERE id < $selectedID ...sort criteria here..;
//Let's say that John is at number 53 when sorted by ID ASC, this means that he'll be on page 50-60 if 10 items per page.
50 = round(53) // round to 10ths.
$num = 50 - 10; // LIMIT starts at page 0, so minus one page (10)
then put this value in the limit
**SELECT my,fields,here FROM table LIMIT $num,10;
This is a common problem and I'm sure there are other solutions other than what I have above.
My Question:
Any easier way to do this? Other creative solutions or ideas (i'm not expecting much) or random babble you can contribute is appreciated.
Ciao!
Dan
Comment