Hi
I need advice on whats wrong with the following code statement?

$purl = ($resultat->product_thumb_image);
echo "<img src='test/image/products/".$purl.".jpg'/>";


$purl is a dynamic variable that should return the ID of the image. i.e. 12DE

somehow the echo fails and it does not display the image.

Any advice? Tks

Recommended Answers

All 3 Replies

$purl = $resultat->product_thumb_image;
echo "<img src='test/image/products/".$purl.".jpg'/>";

Firstly you don't need disambiguation parenthesis when there's no ambiguity. Secondly look at the source of the page that is displayed on and see what is actually output. If it just says <img src='test/image/products/.jpg'/> then $purl isn't being set.

$purl = $resultat->product_thumb_image;
echo "<img src='test/image/products/".$purl.".jpg'/>";

Firstly you don't need disambiguation parenthesis when there's no ambiguity. Secondly look at the source of the page that is displayed on and see what is actually output. If it just says <img src='test/image/products/.jpg'/> then $purl isn't being set.

Either your $purl var is not being set.
Or your image does not exist.
Or the path to the image is invalid. Make sure the directory test/image/products is actually under the base URL.

Just a note: It's good to have double quotes around your HTML attributes.

$purl = $resultat->product_thumb_image;
echo "<img src=\"test/image/products/".$purl.".jpg\"/>";

output will look like: <img src="test/image/products/.jpg"/> That would be valid xHTML.

Also: You don't need string concatenation when using double quotes:

$purl = $resultat->product_thumb_image;
echo "<img src=\"test/image/products/$purl.jpg\"/>";

unless in an ambiguous situation where you would use curly braces around your variable:

$purl = $resultat->product_thumb_image;
echo "<img src=\"test/image/products/{$purl}.jpg\"/>";

1.
$purl = $resultat->product_thumb_image;
2.
echo "<img src='test/image/products/$purl.jpg'/>";

this also use

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.