I need to delete image name from database which is in comma separated form
I used below approach..
names is in database : 31.jpg,31 copy.jpg,110 copy.jpg,110.jpg,110 copy-1.jpg,
After explode it :
Array
(
[0] => 31.jpg
[1] => 31 copy.jpg
[2] => 110 copy.jpg
[3] => 110.jpg
[4] => 110 copy-1.jpg
[5] =>
)
To delete img name with comma : 110.jpg,
Now result : 31 copy.jpg,110 copy.jpg,110.jpg,110 copy-1.jpg,
But why is 110.jpg
in result?
Code for above approach.
<?php
require("include/config.inc.php");
$parent_img_id = 184;
$child_imgs_id = 1221;
$delimg = '110.jpg';
$getInfoChild_imgs = mysql_query("select * from parent where parent_img_id = '$parent_img_id' and child_imgs_id = '$child_imgs_id' and child_imgs like '%$delimg%'") or die(mysql_error());
if(mysql_num_rows($getInfoChild_imgs)>0){
$result = mysql_fetch_array($getInfoChild_imgs);
$child_imgs_name =$result['child_imgs'];
$child_imgs_name = explode(',', $child_imgs_name); // Explode into array
$deleteImgName = $delimg.',';
unset($child_imgs_name[ array_search($deleteImgName, $child_imgs_name) ]);
$child_imgs_name = implode(',',$child_imgs_name);
}
?>