user search engine - go back and forth
I am working on a search engine. Users can search for other users givin specific parameters (such for example age, gender, city, hair color). He is also able to sort the results in different ways.
On the search result page you are able to see 10 profiles and if you click on them, you get to another page (profile page) where you have more information on that single user.
The user who's now on a profil page looking at a specific user should now have to possibility to go back and forth to the next or the previous user from the search result. So you would have to store the specific parameters the user chose and you would also have to run the whole search query over and over again as the user continues to go from one user to the next. This doesn't look nice to me and I thought about storing all user ids temporarily in a session (max 200 to previous users and max 200 to upcoming users) to avoid store the parameters and run the search query every time the user vists another profile page.
Is this a good way or do you have other solutions?
Best regards and thanks in advance for your help,
Wit small number of total matches (under 200 for example), storing IDs in the session is perfectly fine. If you potentially expect a large number of results in the search (in thousands), then a better solution may be to implement a temporary table for the searches. When a search is performed, the IDs and names of the matches are stored in a temporary table against the session ID of the user. You'd need to also have a script that runs periodically and cleans this table of old data.
You could simply store the id's as an array in a session, and then put next/previous links to the next/previous items in the array.