<?php include("../../config/database.php"); $id = $_GET['productId']; $img = $_GET['imageName']; $img_arry = array(); $sql1 =mysqli_query($cn, "select * from `tbl_product` where `id`='$id'"); while($data5 = mysqli_fetch_array($sql1)) { if(!empty($data5['image'])) { $a = explode('$',$data5['image']); foreach($a as $key1) { if($img==$key1) array_push($img_arry,$key1); } foreach($a as $key1) { if($img !=$key1) array_push($img_arry,$key1); } } } $to_img = implode('$',array_unique($img_arry)); $sql = mysqli_query($cn, "UPDATE `tbl_product` SET `image`='$to_img' where `id`='$id' "); if($sql) { echo $to_img; } ?>