<?php
$conn = mysqli_connect("localhost","root","","ecommerce");
if(!$conn){ die("DB Error"); }

if(isset($_POST['ids']) && isset($_POST['table'])){
    $ids = $_POST['ids'];   // array of IDs
    $table = $_POST['table'];

    $pos = 1;
    foreach($ids as $id){
        mysqli_query($conn,"UPDATE $table SET position='$pos' WHERE id='$id'");
        $pos++;
    }
    echo "success";
}
?>
