RyanMinor Posted January 12, 2013 Share Posted January 12, 2013 (edited) 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! Edited January 12, 2013 by RyanMinor Quote Link to comment Share on other sites More sharing options...
salathe Posted January 12, 2013 Share Posted January 12, 2013 You say that the list comes from your database, but is the actual comma-separated string returned directly from there or do you have some PHP constructing that comma-separated list? Quote Link to comment Share on other sites More sharing options...
RyanMinor Posted January 12, 2013 Author Share Posted January 12, 2013 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. Quote Link to comment Share on other sites More sharing options...
salathe Posted January 12, 2013 Share Posted January 12, 2013 (edited) 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. Edited January 12, 2013 by salathe Quote Link to comment Share on other sites More sharing options...
RyanMinor Posted January 12, 2013 Author Share Posted January 12, 2013 I did not know I could do that. Thanks a lot! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.