我需要从数据库中删除以逗号分隔的图像名称
我使用了以下方法..
名称在数据库中:31.jpg,31 copy.jpg,110 copy.jpg,110.jpg,110 copy-1.jpg,
爆炸后:
Array
(
[0] => 31.jpg
[1] => 31 copy.jpg
[2] => 110 copy.jpg
[3] => 110.jpg
[4] => 110 copy-1.jpg
[5] =>
)
用逗号删除img名称:110.jpg,
现在结果:31 copy.jpg,110 copy.jpg,110.jpg,110 copy-1.jpg,
但为什么是110.jpg
结果?
上述方法的代码。
<?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);
}
?>