i have a dropdown list (corresponding to records in the mysql table) where the user selects a numbered slot to place their newly-added item into. lets say there are 4 items in the table, and they select slot 2 from the list. i want the current item in slot 2 to have its "vieworder" field bumped to 3, current item 3 bumped to 4, and so on until all the slots are bumped up a number.
i have the dropdown list working, and it passes the value to a php page with the following code ($chosen_slot is the numeric value passed from the list):
Code: Select all
$slotcount = 1;
while($row = mysql_fetch_array($gifts_sql1_result)){
$check_slot = $rowї"vieworder"];
if($chosen_slot == $check_slot){
$bump = 1;
}
if($bump == 1){
$useslot = $slotcount + 1;
$updatin = "UPDATE gifts_db SET vieworder = $useslot WHERE vieworder = $slotcount";
$updatestuff = mysql_query($updatin, $dbh) or die (mysql_error());
}
$slotcount++;
}the problem is that all of the items that follow this number have the highest number updated into the "vieworder" field (in my above example, instead of the original items - 2, 3, 4 - being updated to 3, 4, 5, they are all updated to 5). i don't understand it, because it seems like it should be doing these incrementally as it steps through the loop, and only affect one row at a time.
any ideas on how to make this work? i'm stumped why it doesn't, seems pretty easy. please save this innocent laptop that is about to be tossed across the room.
- d