Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
209 views
in Technique[技术] by (71.8m points)

how to delete and update a single image from array of images store in a single column of database using php mysqli?

<?php //display.php//
   $con = mysqli_connect("localhost", "root", "", "ist_softtech");
 $i="";
$query="select * from single_field_tbl";
$fire=mysqli_query($con,$query);
$data=mysqli_fetch_array($fire);
$res=$data['imagess'];
$rest=explode(" ",$res);
$count=count($rest)-1;
for($i=0;$i<$count;++$i)
{
    ?>
    <img src="uploads/<?= $rest[$i]?>" height="200px" width="200px"/>
    <?php
}
       echo "<p style='color:green;font-size:26px'>Total ".$count." images found.";


?>

i want to add and update database having multiple images in a single column. i want to add and update database having multiple images in a single column

question from:https://stackoverflow.com/questions/65713988/how-to-delete-and-update-a-single-image-from-array-of-images-store-in-a-single-c

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

$res=$data['imagess']; Are you sure its imagess not images here?

$rest=explode(" ",$res); Some of the file name includes spaces in it so using space to explode is not a good idea. You can use some specific set of characters like: $rest=explode("|||",$res); to divide the filenames.

But why would you have multiple images in a single database column. As far as I have understood, you wanted to have multiple images for a single parameter. Try having two database tables: one for all details and other for images only. For example:

Table 1: id title description

Table 2: id category-id filename

Here category-id is the id to table 1 used as foreign key.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...