I want to display a image from the database by using an img tag. Here is my code:
if( !empty( $cat_id ) ) {
$cats = getImagesByCategory( $cat_id );
foreach( $cats as $image ) {
$id = $image['id'];
echo <<<IMAGE
<img src="images/'.$category['name']. '/' .$image['name'].'" />
IMAGE;
I’m getting a error on the img tag: Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING
I’m clearly concatenating wrong – how can I fix this error?
Your
<img>tag is broken:You’re using
heredocsyntax, you don’t do string concatenation inheredoc. Try something along the lines of:Cheers