w3hello.com logo
Home PHP C# C++ Android Java Javascript Python IOS SQL HTML videos Categories
Parsing one PDO string containing multiple images into multiple img elements

You can use explode() to split the string into individual image paths and then iterate through the list with foreach():

$images =
'http://images.autoexposure.co.uk/AETA83919/AETV85190781_1b.jpg,http://images.autoexposure.co.uk/AETA83919/AETV85190781_2b.jpg,http://images.autoexposure.co.uk/AETA83919/AETV85190781_3b.jpg,http://images.autoexposure.co.uk/AETA83919/AETV85190781_4b.jpg,http://images.autoexposure.co.uk/AETA83919/AETV85190781_5b.jpg,http://images.autoexposure.co.uk/AETA83919/AETV85190781_6b.jpg,http://images.autoexposure.co.uk/AETA83919/AETV85190781_7b.jpg,http://images.autoexposure.co.uk/AETA83919/AETV85190781_8b.jpg,http://images.autoexposure.co.uk/AETA83919/AETV85190781_9b.jpg';

foreach(explode(',', $images) as $image) {
  echo '<img src="'.$image.'">';
}

I would also consider normalizing the database table using a one-to-many relationship.





© Copyright 2018 w3hello.com Publishing Limited. All rights reserved.