Select Images from Mysql Explode

Issue

i have a database with images in the same row.
I can insert images with no problem, saves all, ok. But when in the main page i use the select from and try explode de commas, the first image its ok. But others don’t.

Please check the image with what’s happening and the code:
Check image

            <?php
session_start();

$host = "localhost"; /* Host name */
$user = "root"; /* User */
$password = ""; /* Password */
$dbname = "multiple"; /* Database name */

$con = mysqli_connect($host, $user, $password,$dbname);
// Check connection
if (!$con) {
 die("Connection failed: " . mysqli_connect_error());
}
mysqli_set_charset( $con, 'utf8');

        $query = "select file from student";
    $result = mysqli_query($con,$query);
    $row = mysqli_fetch_assoc($result);
    $images = $row['file'];
    $images = explode(',',$images);
    foreach($images AS $image){
        echo '<img src="uploads/'.$image.'">';
    }
    ?>

I don’t have any spaces in file name, and just show’s the first image. The others put the space betwen the folder and the filename.
Thank you

Solution

You are exploding by ‘,’ but there seems extra space in your string. So, try like below (add a spase for first parameter):

$images = explode(', ',$images);

Answered By – Gamer In The Game

This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply

(*) Required, Your email will not be published