Jump to content

can't find a solution...updating order mysql with array


kirkh34

Recommended Posts

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!

 

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.