<?php

    // others Position

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

    // echo "Position Saved";

    function updatePosition($data, $id) {

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

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

        $query = "UPDATE others SET $imploadAray WHERE o_sl = '$id'";

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

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

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