<?php
	include($_SERVER['DOCUMENT_ROOT'] ."/_ps2020/config/connect.php");

	$sid = $_GET["sid"];
	// $sOrder = $_GET["sOrder"];

		if ($result = $conn->query("DELETE FROM survey WHERE order_id='".$sid."'") === TRUE) {

			// $result = $conn->query("UPDATE survey SET order_id='".$sOrder."' WHERE order_id>'".$sOrder."'");

			$orderID = $sid;

			$res_reAllocateID = $conn->query("SELECT * FROM survey WHERE order_id > '$sid' ");
				if($res_reAllocateID) {
					while ( $row = $res_reAllocateID->fetch_assoc() ){
						// $orderID_new = $orderID + 1;
						$result = $conn->query("UPDATE survey SET order_id = '$orderID' WHERE order_id = ".$row['order_id']." ");
						$orderID++;
					}
				}
		}

   $conn->close();
?>