Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
208 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 Answer

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...