douqiao5314 2016-05-16 08:49
浏览 90
已采纳

从数据库更新单个图像(在数据库中,多个图像以逗号分隔的方式存储)

I want to update single image from database . Multiple images are stored in database with comma separate values.

----------
Table Name 
model_final

id   images                                                               gender 
10   Koala.jpg,Tulips.jpg,Chrysanthemum.jpg,Desert.jpg,Jellyfish.jpg        male

On request of Edit i want to edit just one image. Example : i had store all images separately in database using explode function the are shown in table. -- on click of Koala.jpg i want to update only that image so how to i check it from database.

 if(isset($_GET['edit']))
    {
      $editId = $_GET['edit'];
       $res = $conn->query("select * from model_final where gender='0' and id='$editId'");                              
       $row = mysqli_fetch_assoc($res);
       $image1 = explode(',',$row['images']);
       print_r($image1); 
   }

Print result is ,

Array ( [0] => Koala.jpg [1] => Tulips.jpg [2] => Chrysanthemum.jpg [3] => Desert.jpg [4] => Jellyfish.jpg )

Now i want to update only koala.jpg which on 0th position in image column so how can i check it through query and how can i update only that image.

Please let me know if any other imformation is needed.

EDIT :

I have shown scenario in photo. User can upload upto 100 images so i have to store images in database with comma separeted manner .

enter image description here

EDIT 2:

Table structure of 'images_female'

id image1     image2        image3                image_user_id
1  Koala.jpg  Tulips.jpg  Chrysanthemum.jpg       56


if(isset($_GET['edit']) && isset($_GET['name']))
    {
       $editId = $_GET['edit'];
       $res = $conn->query("select * from model_final where gender='0' and id='$editId'");                              
       $row = mysqli_fetch_assoc($res);
       $image1 = explode(',',$row['images']);
       $image1_0 = $image1['0'];
       $image1_1 = $image1['1'];
       $image1_2 = $image1['2'];
       $image1_3 = $image1['3'];
       $image1_4 = $image1['4'];
       $image1_5 = $image1['5'];
       $image1_6 = $image1['6'];

       $insert_data_images = $conn -> query("insert into images_female (image1,image2,image3,image4,image5,image_user_id) values 
        ('$image1_0','$image1_1','$image1_2','$image1_3','$image1_4','$editId')");

       $update_data_images = $conn -> query("update images_female set image where image_user_id='$editId'");          

     }

// i'm confuse in update query of set data how can i set image on that specific field.

  • 写回答

1条回答 默认 最新

  • douxi9245 2016-05-17 07:37
    关注

    As per the instruction of Duikboot,Reno I made one table.

    ----------
    image_model_separate
    
    image_id image_name user_id
    1         koala.jpg   86
    2         abc.jpg     86
    2         xyz.jpg     86
    

    Through this table i can manage all stuffs of multiple images.

    • Thank you friends for your contributions.
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 要给毕业设计添加扫码登录的功能!!有偿
  • ¥15 kafka 分区副本增加会导致消息丢失或者不可用吗?
  • ¥15 微信公众号自制会员卡没有收款渠道啊
  • ¥15 stable diffusion
  • ¥100 Jenkins自动化部署—悬赏100元
  • ¥15 关于#python#的问题:求帮写python代码
  • ¥20 MATLAB画图图形出现上下震荡的线条
  • ¥15 关于#windows#的问题:怎么用WIN 11系统的电脑 克隆WIN NT3.51-4.0系统的硬盘
  • ¥15 perl MISA分析p3_in脚本出错
  • ¥15 k8s部署jupyterlab,jupyterlab保存不了文件