Skylight_lady Posted June 29, 2011 Share Posted June 29, 2011 Hi Guys, I have an up/down ordered list to display which services should be ahead of the others. Below is my code: $menu_id = $_GET['page_id']; $page_order = $_GET['page_order']; if ($_GET['do'] == 'up') { mysql_query("UPDATE services SET menu_order = '$page_order' +1 WHERE ID != '$menu_id' AND menu_order < '$page_order'") or die(mysql_error()); mysql_query("UPDATE services SET menu_order = menu_order -1 WHERE ID = '$menu_id'") or die(mysql_error()); header("Location: /services/view/"); } if ($_GET['do'] == 'down') { mysql_query("UPDATE services SET menu_order = '$page_order' -1 WHERE ID != '$menu_id'"); mysql_query("UPDATE services SET menu_order = menu_order +1 WHERE ID = '$menu_id'"); header("Location: /services/view/"); } The code above is accessed via this link: <a href="/services/view/index.php?do=up&page_id=<?php echo $id; ?>&page_order=<?php echo $menu_order; ?>"> Now, if i have a table setup as: IDmenu_order 21 53 42 And click on the links button to go "up" one for the ID "5" i get the following: IDmenu_order 24 52 44 I can't seem to see what is wrong with the code but ...... the ID of 2 and 4 are wrong. If i click the down button on the same ID 5 which will have do=down in the link then i get: IDmenu_order 21 53 41 I would appreciate any help with this. Quote Link to comment https://forums.phpfreaks.com/topic/240722-updown-ordered-list-problem/ Share on other sites More sharing options...
xyph Posted June 29, 2011 Share Posted June 29, 2011 There's a few things wrong there. If you type out what your queries are doing in english you'll find it. I'll give you code and DB dump of how I'd do this in a moment Quote Link to comment https://forums.phpfreaks.com/topic/240722-updown-ordered-list-problem/#findComment-1236443 Share on other sites More sharing options...
xyph Posted June 29, 2011 Share Posted June 29, 2011 Hold the horses. PHPFreaks has a tutorial on this already. http://www.phpfreaks.com/tutorial/php-custom-list-order Will still code something for you though. Quote Link to comment https://forums.phpfreaks.com/topic/240722-updown-ordered-list-problem/#findComment-1236444 Share on other sites More sharing options...
Skylight_lady Posted June 29, 2011 Author Share Posted June 29, 2011 I already have it sorted. Thanks a million. I did check that tutorial on my iphone, i dunno why i didn't follow it. Thanks again. Quote Link to comment https://forums.phpfreaks.com/topic/240722-updown-ordered-list-problem/#findComment-1236462 Share on other sites More sharing options...
Skylight_lady Posted June 29, 2011 Author Share Posted June 29, 2011 Hi again I noticed from that tutorial on phpfreaks is that it did not explain how you can "delete" and then "update" (the rest of the table that has a higher value .........to one value less than its original list order). Quote Link to comment https://forums.phpfreaks.com/topic/240722-updown-ordered-list-problem/#findComment-1236484 Share on other sites More sharing options...
xyph Posted June 29, 2011 Share Posted June 29, 2011 There's an answer in the comments, but I'll show you my approach to it. Quote Link to comment https://forums.phpfreaks.com/topic/240722-updown-ordered-list-problem/#findComment-1236487 Share on other sites More sharing options...
Skylight_lady Posted June 29, 2011 Author Share Posted June 29, 2011 I should learn to scroll down. Thanks, have it sorted. Now i have a challange......... PAGINATION. I've seen the tutorial phpfreaks but it is confusing as it's asking me to add numbers to a column when i'm clueless on: adding it to my original table how to add this numbers column's data when all the data in that page is inserted from a different page Quote Link to comment https://forums.phpfreaks.com/topic/240722-updown-ordered-list-problem/#findComment-1236599 Share on other sites More sharing options...
xyph Posted June 29, 2011 Share Posted June 29, 2011 What? Quote Link to comment https://forums.phpfreaks.com/topic/240722-updown-ordered-list-problem/#findComment-1236613 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.