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... Link to comment https://forums.phpfreaks.com/topic/139184-move-up-or-down-records/ 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. Link to comment https://forums.phpfreaks.com/topic/139184-move-up-or-down-records/#findComment-727980 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? Link to comment https://forums.phpfreaks.com/topic/139184-move-up-or-down-records/#findComment-727990 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? Link to comment https://forums.phpfreaks.com/topic/139184-move-up-or-down-records/#findComment-728000 Share on other sites More sharing options...
s.mujtaba Posted January 2, 2009 Author Share Posted January 2, 2009 the previous entry Link to comment https://forums.phpfreaks.com/topic/139184-move-up-or-down-records/#findComment-728004 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. Link to comment https://forums.phpfreaks.com/topic/139184-move-up-or-down-records/#findComment-728010 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 Link to comment https://forums.phpfreaks.com/topic/139184-move-up-or-down-records/#findComment-728013 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. Link to comment https://forums.phpfreaks.com/topic/139184-move-up-or-down-records/#findComment-728016 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 :( Link to comment https://forums.phpfreaks.com/topic/139184-move-up-or-down-records/#findComment-728021 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. Link to comment https://forums.phpfreaks.com/topic/139184-move-up-or-down-records/#findComment-728022 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.