zrweber Posted January 11, 2011 Share Posted January 11, 2011 How hard would something like this be? I have a database with all my users. I need an empty list and when a user clicks a button "Add me to the list" they are added to the first position in the list Slots 1. Tom 2. 3. 4. 5. Later, Jerry wants to be added to the list. So this happens Slots 1. Jerry 2. Tom 3. 4. 5. More people join the list 1. Bob 2. John 3. Jerry 4. Tom 5. Tom gets upset clicks the same button to join the list again, and he's bumped back up to first place. Slots 1. Tom 2. Bob 3. John 4. Jerry 5. Is this possible? And is so, how would I go about getting started on such a thing? I've been using PHP for about a year and a half. Quote Link to comment https://forums.phpfreaks.com/topic/224122-a-list-where-you-can-move-positions-of-list-items-hmm/ Share on other sites More sharing options...
Psycho Posted January 12, 2011 Share Posted January 12, 2011 Of course it is possible - using PHP for a year and a half I would think you should have at least a basic understanding of what would be required. Not knowing how you intend to use this information it is difficut to give a suggestion on the best wat to implement. First, you need some way to know what name to add to the list. Are users "logged in" to the site where you can get there name dynamically or do you need the user to supply their name. Second, how do you want to store the information? How you plan to use the information might help decide this. You could use a database - or if this is for a very limited number of users you might be able to use a flat file. Third, create a form with the button (and possibly the text field to enter their name). Fourth, Create a processign page to receive the form data (could actually be the same as the form page if you have it post to itself). That page will take the input, verify it is valid (i.e. not null, not malicious, etc). Then, check if the value already exists in the list. If not, add it to the top of the list and move all the other records down. If so, remove the value from it's current position and move to the top of the list. This would actually be much easier with a database by just setting a modification timestamp for each record. Then just display the records based upon the timestamp. Quote Link to comment https://forums.phpfreaks.com/topic/224122-a-list-where-you-can-move-positions-of-list-items-hmm/#findComment-1158140 Share on other sites More sharing options...
zrweber Posted January 12, 2011 Author Share Posted January 12, 2011 I have an idea of how I'm going to do it. I've only minorly used PHP, I know enough to make a pretty decent user registration and what not. And yes, I already have a data base where the people using this list will be registered and what not. My question is, say someone adds themselves to the list or bumps themselves up, how do I go about pushing everyone else down? Quote Link to comment https://forums.phpfreaks.com/topic/224122-a-list-where-you-can-move-positions-of-list-items-hmm/#findComment-1158575 Share on other sites More sharing options...
Rayhan Muktader Posted January 12, 2011 Share Posted January 12, 2011 mjdamato is suggesting that you don't push any one down. That would be a lot of extra work. Instead, save the id, name and button_pushed_time_stamp (you should rename this one) in the database. example: 1 Tom 2011-01-10 2 Dick 2011-01-09 3 Harry 2011-01-08 If Harry pushes the button again on the 11th then the table will hold: 1 Tom 2011-01-10 2 Dick 2011-01-09 3 Harry 2011-01-11 Then you can you can always order the data by who pushed the button last: SELECT * FORM `table` ORDER BY `button_pushed_time_stamp` DESC This will return: 3 Harry 2011-01-11 1 Tom 2011-01-10 2 Dick 2011-01-09 Hope this helps. Rayhan Muktader Quote Link to comment https://forums.phpfreaks.com/topic/224122-a-list-where-you-can-move-positions-of-list-items-hmm/#findComment-1158594 Share on other sites More sharing options...
zrweber Posted January 12, 2011 Author Share Posted January 12, 2011 Thanks guys! I got it from here Quote Link to comment https://forums.phpfreaks.com/topic/224122-a-list-where-you-can-move-positions-of-list-items-hmm/#findComment-1158628 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.