Select Images from Mysql Explode

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


$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


Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.

Method 1

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);

All methods was sourced from or, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

0 0 votes
Article Rating
Notify of

Inline Feedbacks
View all comments
Would love your thoughts, please comment.x