kirkh34 Posted December 17, 2010 Share Posted December 17, 2010 okay I am using a jquery plugin to re-arrange images which are in mysql and they have their own "order_number" ... when i re-arrange stuff the new order is put into a hidden field in a form and i have it along with another hidden field with their current order... when submitted I combine these two fields in an array so the key is the original order and the value is the new order ....i have 12 images... Array ( [1] => 1 [2] => 2 [3] => 3 [4] => 4 [5] => 5 [6] => 6 [7] => 7 [8] => 8 [9] => 9 [10] => 10 [11] => 11 [12] => 12 ) this is what is what the array looks like... i have a foreach loop with a mysql query but things get kind of weird when you try to do it this way $num = $_POST['old_num']; $num = unserialize($num); $sort = $_POST['sortOrder']; $sort = explode(',', $sort); if ($_POST){ $combine = array_combine($num, $sort); foreach($combine as $key => $value){ mysql_query("UPDATE shirts SET order_number='$value' WHERE order_number='$key' ") or die(mysql_error()); } when you do this lets say for example we have the image with order number "1" get switched with the image order number "2"..... the database first updates with number 1 which becomes 2... then when it goes to number "2"... at this point... the first image gets switched back to number 1.... so 1 becomes 2 then the new 2 becomes 1 again and the other 2 becomes 1 also. I can not think of another way I could update mysql with the correct order numbers... If anyone has any ideas or other solutions I am open to all suggestions... thank you! Quote Link to comment https://forums.phpfreaks.com/topic/221953-cant-find-a-solutionupdating-order-mysql-with-array/ Share on other sites More sharing options...
suma237 Posted December 17, 2010 Share Posted December 17, 2010 can you post the array $combine? Quote Link to comment https://forums.phpfreaks.com/topic/221953-cant-find-a-solutionupdating-order-mysql-with-array/#findComment-1148532 Share on other sites More sharing options...
kirkh34 Posted December 17, 2010 Author Share Posted December 17, 2010 the array at the top is the array combine printed out when nothing is arranged differently... Quote Link to comment https://forums.phpfreaks.com/topic/221953-cant-find-a-solutionupdating-order-mysql-with-array/#findComment-1148535 Share on other sites More sharing options...
PFMaBiSmAd Posted December 17, 2010 Share Posted December 17, 2010 You need to use the id of the row in the WHERE clause, not the current order_number. Quote Link to comment https://forums.phpfreaks.com/topic/221953-cant-find-a-solutionupdating-order-mysql-with-array/#findComment-1148537 Share on other sites More sharing options...
kirkh34 Posted December 17, 2010 Author Share Posted December 17, 2010 of course... wow how can my mind stray from such the simplest solution!! thanks! Quote Link to comment https://forums.phpfreaks.com/topic/221953-cant-find-a-solutionupdating-order-mysql-with-array/#findComment-1148541 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.