点击按钮的排序列

I have a table as city which stores the information of entered city. In city table i've one columns name as city_order which stores the order of city to display (1,2,3...etc). When listing the order, i've up and down arrow in the table. When user clicks on up arrow of any city, i've to change the order of that city as well as the city above it. I am calling ajax function on the click of the arrow and getting the order of the clicked city. If up arrow is clicked then i am chaging the order of the previous city to current order and vice versa. If down arrow is clicked i am chaging the order of the next city to current order and vice versa. This thing is not working as expected. Please find below ajax code.

$cityid = $_REQUEST["cityid"];
$cityorder = $_REQUEST["cityorder"];
$type = $_REQUEST["type"];
if(isset($type) && $type == "up"){
    $newcityorder = $_REQUEST["cityorder"] - 1;
}else{
    $newcityorder = $_REQUEST["cityorder"] + 1;
}
$productid = $_SESSION["productid"];
$dclass1->query("update tbl_city set city_order = '$cityorder' where city_order = '$newcityorder' AND item_id = '$productid'");
$dclass1->query("update tbl_city set city_order = '$newcityorder' where cityid = '$cityid'");