カンマ区切り形式の画像名をデータベースから削除する必要があります
以下のアプローチを使用しました。
名前はデータベースにあります: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);
}
?>