s.mujtaba Posted January 2, 2009 Share Posted January 2, 2009 Hi... How to move up or down records in database by press a button or hyperlink like this: idmenu 1menu1 2menu2 3menu3 when i press move up to menu3, it will be: idmenu 1menu1 3menu3 2menu2 Bye... Quote Link to comment Share on other sites More sharing options...
Altec Posted January 2, 2009 Share Posted January 2, 2009 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. Quote Link to comment Share on other sites More sharing options...
s.mujtaba Posted January 2, 2009 Author Share Posted January 2, 2009 But if the next id = 4 and the back id = 1 how do i move up the record? Quote Link to comment Share on other sites More sharing options...
Altec Posted January 2, 2009 Share Posted January 2, 2009 I'm not understanding your example. If what equals 4, the selected entry or the previous entry relative to the selected entry? Quote Link to comment Share on other sites More sharing options...
s.mujtaba Posted January 2, 2009 Author Share Posted January 2, 2009 the previous entry Quote Link to comment Share on other sites More sharing options...
DarkWater Posted January 2, 2009 Share Posted January 2, 2009 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. Quote Link to comment Share on other sites More sharing options...
s.mujtaba Posted January 2, 2009 Author Share Posted January 2, 2009 Thanks, but i want it to move up by pressing a hyperlink Quote Link to comment Share on other sites More sharing options...
DarkWater Posted January 2, 2009 Share Posted January 2, 2009 *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. Quote Link to comment Share on other sites More sharing options...
s.mujtaba Posted January 2, 2009 Author Share Posted January 2, 2009 Why? I'm making a script and I need it :( Quote Link to comment Share on other sites More sharing options...
DarkWater Posted January 2, 2009 Share Posted January 2, 2009 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. 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.