danieliser Posted March 31, 2009 Share Posted March 31, 2009 Ok I am creating an application that will display a group of random user_codes. The user veiwing them will check them off and hit a button that will repeat the process. My problem lies in the memory of those checked boxes. Once they are checked they should never be displayed again. I can't think of an easy way to do this without a huge server load. Only thing I can think of is a table for each user containing a line for each other user and keeping track like that. But that would create massive databases if I had say 10000 users with 9999 lines in each of thier tables. I hope there is a better way to do it. Thanks in advance. Quote Link to comment Share on other sites More sharing options...
Daniel0 Posted March 31, 2009 Share Posted March 31, 2009 Store them using sessions and remove indices as you go. Quote Link to comment Share on other sites More sharing options...
danieliser Posted March 31, 2009 Author Share Posted March 31, 2009 but wouldnt that require a complete list to begin with? say i did it that way and 20 more users joined.. im really want to shy away from a 10000 line user table for each user.. im thinking of using ajax to load the app.. dont know if that changes anything.. Quote Link to comment Share on other sites More sharing options...
Daniel0 Posted March 31, 2009 Share Posted March 31, 2009 Well, say you have an array like this: $_SESSION['stuff'] = array( 'foo' => 'bar', 'hello' => 'hi', 'somebody' => 'me', ); You can then generate your checkboxes using the key-value pair, i.e. foreach ($_SESSION['stuff'] as $key => $value) { echo "<input type='checkbox' name='stuffRemove[]' value='{$key}' id='stuff_{$key}'> <label for='stuff_{$key}'>{$value}</label>"; } When the form has been submitted you'll have $_POST['stuffRemove'] which you can use to delete elements from the $_SESSION['stuff'] array: foreach ($_POST['stuffRemove'] as $index) { if (isset($_SESSION['stuff'][$index])) { unset($_SESSION['stuff'][$index]); } } Repeat as many times as you need. Quote Link to comment Share on other sites More sharing options...
danieliser Posted March 31, 2009 Author Share Posted March 31, 2009 So if I got what you said correctly then the array would be my random group of users. The session would be basically a list of all the ones checked off and on the back end I would only need to store the session variable in a table with the current users id. Then when they log back in recall the session variable and have it query for 10 that aren't in the $session. Does that sound close? Quote Link to comment Share on other sites More sharing options...
Daniel0 Posted March 31, 2009 Share Posted March 31, 2009 The array stored in the session would be the remaining items. The array from the POST request would be the indexes that were checked. The session variable is transferred on each request without need to use a database. See this tutorial. Quote Link to comment Share on other sites More sharing options...
danieliser Posted March 31, 2009 Author Share Posted March 31, 2009 Ok. But I need to be able to store the list for the user to be able to log in at a later time and continue without getting any repeats. And allow for new users to be added to the random list. Quote Link to comment Share on other sites More sharing options...
danieliser Posted March 31, 2009 Author Share Posted March 31, 2009 I would prefer that the users history were kept on the server so that they can login from different computers or phones etc.. using session variables or cookies wouldnt allow that i dont think.. Quote Link to comment Share on other sites More sharing options...
Daniel0 Posted March 31, 2009 Share Posted March 31, 2009 Then you have to store it in the database. What exactly are you trying to do though? Quote Link to comment Share on other sites More sharing options...
danieliser Posted March 31, 2009 Author Share Posted March 31, 2009 Its for a game basically.. Each user in the game gets an id number xxx-xxx-xxx.. You then add friends by thier id. I want the users to be able to register with thier id on my site.. then get a list of other registered users which they can check off as they add them in game. And as there could be 25000 + users as the game has closer to 100k users each user could add them all with no duplicates.. once they have all been checked off the user would only see newly registered users which would then be checked off. Does that make since? As there could potentially be a lot of users and a lot of codes for each user to view/check I need it to remember them not just in session but permanently. And with that many users i would need a simpler way to log the ones done rather than a table for each user containing all the other users.. that would just get exponentially to big at some point. Thanks again for your help Quote Link to comment Share on other sites More sharing options...
Daniel0 Posted March 31, 2009 Share Posted March 31, 2009 You want your users to check off several thousands of users? Quote Link to comment Share on other sites More sharing options...
danieliser Posted March 31, 2009 Author Share Posted March 31, 2009 Yes basically. In the game you can use (Your Level x 10) members that you've added to your friends list when fighting. So a level 100 would be able to use up to 1000 friends to fight with. There is no level cap that I've seen so a player at lvl 1000 would need 10k friends to fight at his best. So yes each person could add as many as possible. This is basically a networking site for players of that game. The more the better. Except on my end LOL. The more the more resources needed for each cycle which is what I need to reduce. Quote Link to comment Share on other sites More sharing options...
Daniel0 Posted March 31, 2009 Share Posted March 31, 2009 Right, okay. No offense, but that's a pretty stupid design. Nobody is going to wade through a list containing hundreds or thousands of users. It's simply to cumbersome. You might want to check up on HCI. It'll also result in poor performance. Your list of combinations will be growing exponentially, and with a sizable user base this will quickly become a bottleneck. Why not simply allow users to add a username as friend (and return an error if they don't meet the friend requirements). Assuming you're able to view other users' profiles, you could add a "Add as friend" link if the formal requirements are met. Again, check the requirements when the link is clicked. Quote Link to comment Share on other sites More sharing options...
danieliser Posted March 31, 2009 Author Share Posted March 31, 2009 Although it's hard to believe people will sit there and do it haha. The point of the site isn't actually a social network. More of a tool to drive your group size in the game. There are several sites that allow people to list their friend code but they don't allow the person veiwing them to differentiate the ones they have done from the ones they haven't. If this isn't feasable then I can accept that. I was trying to make my site stand out from the rest. Quote Link to comment 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.