<?php 
require_once "connect.php";

$action = $mysqli->real_escape_string($_POST['action']); 
$updatelistarray = $_POST['listarrayitem'];

$itemsarray = array();
foreach ($updatelistarray as $idvalue) {
		
$result1 = $mysqli->query("SELECT priority FROM items WHERE insert_id=$idvalue");
$row = $result1->fetch_array();
$pid=$row['priority'];	  

$itemsarray[] = $pid;
}

$minpriority = min($itemsarray);
$listingcounter = $minpriority;

if ($action == "updatelisting"){
	
	foreach ($updatelistarray as $idvalue) {
		
	$mysqli->query("UPDATE items SET priority = " . $listingcounter . " WHERE insert_id = " . $idvalue);
	
	$listingcounter = $listingcounter + 1;	
	}
}
?>