Jump to content

Add string to beginning of each item in comma separated list


RyanMinor

Recommended Posts

I have a comma separated list of thumbnails coming from my database for each album. I need to add the path to the beginning of each element like so

 

$event['thumbnails'] = thumb.jpg, thumb2.jpg, thumb3.jpg, thumb4.jpg

 

I need to make it so the list above looks like http://site.com/medi...humbs/thumb.jpg, http://site.com/medi...umbs/thumb2.jpg, http://site.com/medi...umbs/thumb3.jpg, http://site.com/medi...umbs/thumb4.jpg

 

How would I go about doing that and ensure that it stays as a comma separated list instead of turning it into an array? Thanks!

This is my database query

 

SELECT event.*, GROUP_CONCAT(photo_thumbnail) as thumbnails
FROM event
LEFT JOIN photo ON event_id = photo_event
WHERE event_user = ?
GROUP BY event.event_id;

 

So I am left with an array in which one of the keys is a comma separated list of thumbnails. I am doing it like this because I am using the live jQuery thumbnail script.

Why not do all the hard work in the query?

 

SELECT event.*, GROUP_CONCAT(CONCAT(?, photo_thumbnail) SEPARATOR '|') AS thumbnails …

 

Then pass in the URL prefix as a query parameter, like you do with event_user.

 

This would return the thumbnail URLs in the correct format that you can just plonk into the data-images attribute in your HTML.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.