Jump to content

move up or down records


s.mujtaba

Recommended Posts

Basically you're going to UPDATE the `id` of the entry above or below (depending on the way you move said entry) as well as the `id` of the selected entry. You won't physically move the records in the database, but you'll "reorder" them.

Link to comment
Share on other sites

Okay, first of all, I'd suggest reading the latest PHPFreaks tutorial.  It's called "Custom List Order" or something like that.  It explains this better than I can in a little post, so go check it out.

 

Anyway, the basic concept is simple.  You have a position column in your database, which in order to move something down, you just flip positions with the row below it, and to move up, you just switch positions with the row below it.

 

+----+--------------------+----------+
| id | name               | position |
+----+--------------------+----------+
|  1 | DarkWater          |        1 | 
|  2 | Bill Gates         |        2 | 
|  3 | Some random person |        3 | 
|  4 | Your Mother        |        4 | 
+----+--------------------+----------+

 

Okay.  Now, if I wanted Bill Gates to be first, I could just flip position numbers with the one above it.

+----+--------------------+----------+
| id | name               | position |
+----+--------------------+----------+
|  1 | DarkWater          |        2 | 
|  2 | Bill Gates         |        1 | 
|  3 | Some random person |        3 | 
|  4 | Your Mother        |        4 | 
+----+--------------------+----------+

 

And when you do a SELECT, do it based on the position column.  The tutorial covers it MUCH more in depth than I did.  Good luck getting this to run smoothly; sometimes it's tricky.

Link to comment
Share on other sites

*facepalm*

So you code PHP to flip the IDs when you press a hyperlink.  We are not going to do this for you, we're just going to help.  I gave you a major stepping stone, and I really, really hoped you could apply it to your needs.  Read the tutorial.

Link to comment
Share on other sites

Why? I'm making a script and I need it  :( :(

 

Okay, so learn how to do it.  There's plenty of references.  If you really need it done and you can't be bothered to put some time in to learn the concept (which is not that difficult once you get it), go to the Freelance forum and pay someone to do it.

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.