rachelk Posted July 27, 2009 Share Posted July 27, 2009 I'm a beginner at php so I apologise if I'm not making much sense here! I have an array that I'd like to be ordered randomly (not just ordered randomly and then stuck that way forever, but shuffled on each visit). The array is paginated though, so if I use the "shuffle ($objects)" function, when I go to the second page everything is shuffled all over again and sometimes the objects that appeared on the first page also appear on the subsequent page.. I'm wondering if there was any way to prevent this happening? Thanks in advance for any help. Link to comment https://forums.phpfreaks.com/topic/167572-solved-randomly-displaying-an-array/ Share on other sites More sharing options...
vineld Posted July 27, 2009 Share Posted July 27, 2009 Unless the user is logged in you might want to identify the visitor by setting a session variable upon the first visit. That way you can recognize him / her by checking for the session variable and if it is set, don't reshuffle the array. Link to comment https://forums.phpfreaks.com/topic/167572-solved-randomly-displaying-an-array/#findComment-883691 Share on other sites More sharing options...
rachelk Posted July 27, 2009 Author Share Posted July 27, 2009 Thanks for your help! Would this be right? <?php session_start(); $_SESSION['visited'] = {true} if(isset($_SESSION['visited'])){ } else {shuffle ($objects)} ?> Link to comment https://forums.phpfreaks.com/topic/167572-solved-randomly-displaying-an-array/#findComment-883704 Share on other sites More sharing options...
vineld Posted July 27, 2009 Share Posted July 27, 2009 You can not set the session variable prior to your check, then you will never shuffle since it will always be set Link to comment https://forums.phpfreaks.com/topic/167572-solved-randomly-displaying-an-array/#findComment-883708 Share on other sites More sharing options...
rachelk Posted July 27, 2009 Author Share Posted July 27, 2009 Got it, thanks for your help, it works! Link to comment https://forums.phpfreaks.com/topic/167572-solved-randomly-displaying-an-array/#findComment-883717 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.