Jump to content

move up or down records


s.mujtaba

Recommended Posts

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.

*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.

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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.