Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

save and selectively display query results

Status
Not open for further replies.

RobBroekhuis

Technical User
Joined
Oct 15, 2001
Messages
1,971
Location
US
Using php/mysql to display search results, with 20 results shown per page. Since the results come from an actively used database, I'd prefer not to re-execute the search query for each page (e.g., page 3 would have results 41-60), since the number of search hits might change between page displays. That brings me to two questions:

* can I store a query resource identifier as a session variable, to refer to the same query results on the next page?
* is there an easy way to pick out, say, records 41 through 60 out of the query results, without having to loop through the first 40 with mysql_fetch_row?



Rob
[flowerface]
 
myql_fetch_array retrieves ONE RECORD as an associative array. You still need to call the function as many times as you need records. At least, that's how I've always used it.

Rob
[flowerface]
 
You cannot store a resource handle for use from one script to another. The query must be run for each run of the script.

If you want to fetch specific rows from a possible MySQL return (say, rows 20-30 of a select statement that would return 100 rows), then use the MySQL LIMIT clause (documented on the page for SELECT:
If the query
Code:
SELECT * from the_table
would return 100 rows, but you only want rows 20-30, then you would modify the query to read
Code:
SELECT * FROM the_table LIMIT 19,10



Want the best answers? Ask the best questions: TANSTAAFL!!
 
I agree - and that's how I'm doing it now. A minor problem arises when something like this example occurs:

While user is viewing page 3 (records 41-60), another user adds a new record which meets the search criteria. Now the first user goes to view page 2, which has records 21-40. But the ORIGINAL record 40 is now record 41, so that the user never sees this one (unless he goes back to page 3). Am I making sense?


Rob
[flowerface]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top