Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial


nicholas maddren
nicholas maddren
12,793 Points

Display images when a MySQL column contains more than one image url within the string

Hey guys I am just displaying images from my database using PHP PDO, I am just wondering how I can do this...

The image column within my database contains about 6 image links separated by commas, how can I display these links in unique img elements?

Here is an example of the column string: http://images.autoexposure.co.uk/AETA83919/AETV10725693_1b.jpg,http://images.autoexposure.co.uk/AETA83919/AETV10725693_2b.jpg

There are only two images in that string however there will be more in other rows.

How can I print those images links into their own img src elements?

Thanks, Nick

1 Answer

Ali Hamra
Ali Hamra
1,386 Points

You should use "explode".

$string = "http://images.autoexposure.co.uk/AETA83919/AETV10725693_1b.jpg,http://images.autoexposure.co.uk/AETA83919/AETV10725693_2b.jpg" $array = explode(',', $string); this will separate the string content when finding the comma into array

Let me know if this works for you !