Jump to content

A list, where you can move positions of list items.. Hmm


zrweber

Recommended Posts

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.  ;D

 

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.