Nickmadd Posted September 13, 2014 Share Posted September 13, 2014 (edited) Hey guys I'm having an issue trying to get my PHP to display the first url of my exploded string and non of the others. The SQL table column contains strings like this: http://www.imgurl.com/image.jpg,http://www.imgurl.com/image2.jpg,http://www.imgurl.com/image3.jpg,http://www.imgurl.com/image4.jpg I am currently using this code to display the table column onto my front end: <img src="'.implode('"/><img src="',explode(',', $row["PictureRefs"])[0]).'"/> However I am getting a parse error due to the fact I have added [0] to the code to try and display only the first exploded part of the string. Any idea how I can only display the first exploded part of the string? Thanks Edited September 13, 2014 by Nickmadd Quote Link to comment Share on other sites More sharing options...
Solution kicken Posted September 13, 2014 Solution Share Posted September 13, 2014 If you're only displaying one, then you don't need the implode statement. echo '<img src="'.(explode(',', $row["PictureRefs"])[0]).'"/>'; If you get a syntax error due to the [0] then your PHP version is not new enough for that syntax. You will need to assign the results of the explode to a variable then use that variable instead. $var = explode(',', $row["PictureRefs"]); echo '<img src="'.$var[0].'"/>'; Note that having delimiter-separated values stored in the database like that is typically a sign of bad design and you should re-think your database design. 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.