Home > database >  Select Images from Mysql Explode
Select Images from Mysql Explode

Time:10-24

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

CodePudding user response:

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