I’ve been looking for the solution for this and I’m sure it’s an easy fix, but I can’t figure it out. I’m basically querying for products in my database. I’ve stored thumbnail images in a folder corresponding to the product_id. The only thing I can’t get to display is the image. Please fill me in on where I’m going wrong. Thanks a ton!
$products = get_products();
if (empty($products)) {
echo '<p>No products to display yet</p>';
} else {
foreach ($products as $product) {
echo '<img src="../uploads/thumbs/<?php echo $product_id; ?>/<?php echo $product_id; ?>.jpg", <p><a href="view_product.php?product_id=', $product['id'], '">', $product['name'], '</a><br/>', $product['description'], '...<br/>
</p>';
}
}
It’s kind of hard to tell without seeing the array structure that it returns, but if the image filename is just the product Id, then this should work.
You were trying to do string concatenation with a comma? DOes that work?
String concatenation has to be done like:
Try this:
Definitely accept all answers that are correct, or helped you.
What you were doing wrong:
YOu have to specify array keys like $product[‘id’] not $product_id, It looks like that variable does not exist.
Edit:
Variables inside Strings: