<?php

    // Category Position

    foreach ($_POST["value"] as $key => $value) {
        $data["dpos"] = $key + 1;
        updatePosition($data, $value);
    }

    // echo "Position Saved";

    function updatePosition($data, $id) {

        include "../../db.php";

        if(array_key_exists("did", $data)){
            $data["did"] = $this->real_escape_string($data["did"]);
        }
        foreach ($data as $key => $value) {
            $value="'$value'";
            $updates[]="$key = $value";
        }
        $imploadAray=  implode(",", $updates);

        $query = "UPDATE doctor SET $imploadAray WHERE did = '$id'";

        // echo '<pre>';print_r($query);exit();

        $result = mysqli_query($con, $query) or die(mysqli_error($con));

        if ($result) {
            return "Category is position";
        } else {
            return "Error while updating position";
        }
    }
?>