<?php
    include("../include/config.php");
    
    $data_row_id = mysqli_real_escape_string($conn,$_POST['data_row_id']);
    $data_img = mysqli_real_escape_string($conn,$_POST['data_img']);
    
  
    
    $sqlAssign1 = "SELECT * FROM `news` WHERE `news`.`id`='$data_row_id'";
    $resultAssign1 = mysqli_query($conn, $sqlAssign1);											
    if (mysqli_num_rows($resultAssign1) > 0) {
        while($rows = mysqli_fetch_assoc($resultAssign1)) {
            $more_img_gallery = $rows['images'];
        }
        
    }
    
$myArray = explode(',', $more_img_gallery);
$countArr= count($myArray);
$count=0;
$remain_img='';
$remove_img = $data_img;
$remainCount=$countArr-1;
foreach ($myArray as $gl_img){
    $count += 1;
    if($gl_img==$remove_img){
        //unlink("uploads/$gl_img");
        $count -= 1;
    }else{
        if($count==$remainCount){
            $remain_img .= $gl_img;
        }else{
            $remain_img .= $gl_img .",";
        }
    }
    
}
  
$query="UPDATE `news` SET `images` = '$remain_img' WHERE `news`.`id` = '$data_row_id'";
if (mysqli_query($conn, $query)) { 
    $msg['status'] = "true";
    $msg['msg'] = "Successfully deleted";
    echo json_encode( $msg );
    exit;
}else{
    $msg['status'] = "false";
    $msg['msg'] = "failed Something is Wrong ";
    echo json_encode( $msg );
     exit;
}
    
    
    
    
?>