poleposters Posted October 19, 2008 Share Posted October 19, 2008 Hi, I'm building a business directory.When a user searches for a business I want the results to display randomly, as it would be unfair to order by date or alphabetically. This is simple enough. Except I need to be able to save the random selection for pagination. This way there is no repeat of records and the user can view all the records available. Is this possible? And if so, can anyone help with some strategies? Thanks. Quote Link to comment https://forums.phpfreaks.com/topic/129119-selecting-random-records-and-holding-for-pagination/ Share on other sites More sharing options...
JasonLewis Posted October 20, 2008 Share Posted October 20, 2008 Hmmm.. Well I suppose you could store the displayed records in a session variable as an array for the current search term. So, store the ID's of the fields like so: array( "search_term" => array( "1" => array(1,7,4,89,41,22,14), "2" => array(65,32,51,3,8,18,29), ), ); Where you have the search term as the key then the value being another array. This array will hold the page data. So when you view the first page store all the ID's under the key 1 then when you go to the second page check that the selected IDs are NOT in that array, when displaying the records add them to the page 2 array. Then when you go back a page you could check to see if the page numbers key exists, if it does then display the records in the array, otherwise grab new records and check the array. Make sense? I don't think there are any flaws with that idea. Then if they search again with the same term I suppose you could remove the array already in there and add a new one. Good luck. Quote Link to comment https://forums.phpfreaks.com/topic/129119-selecting-random-records-and-holding-for-pagination/#findComment-669871 Share on other sites More sharing options...
waynew Posted October 20, 2008 Share Posted October 20, 2008 If you already know the basics of pagination: SELECT * FROM example ORDER BY RAND() LIMIT $offset, $rows Quote Link to comment https://forums.phpfreaks.com/topic/129119-selecting-random-records-and-holding-for-pagination/#findComment-669919 Share on other sites More sharing options...
sasa Posted October 20, 2008 Share Posted October 20, 2008 If you already know the basics of pagination: SELECT * FROM example ORDER BY RAND() LIMIT $offset, $rows you mast use seed with RAND() function and random array is same for same seed Quote Link to comment https://forums.phpfreaks.com/topic/129119-selecting-random-records-and-holding-for-pagination/#findComment-669960 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.