Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Echoing PHP within HTML

Tags:

html

php

echo

I am currently trying to create a shopping cart for my website and I have images of products stored in a database and I want to include them within <img src> . By putting $get_row[imagesrc] within the src. I need to know the correct way to add it to the below code as I dont fully understand the ' and . tags

    echo '<p>'.$get_row['name'].'<br/>'.$get_row['description'].'<br/>'.$get_row['imagesrc'].
'<br/>&pound;'.number_format($get_row['price'],2).'<a href="cart.php?add='.$get_row['id'].'">Add</a></p>';
like image 870
Ben Thompson Avatar asked Jun 15 '26 08:06

Ben Thompson


2 Answers

This should achieve what you're looking for:

echo '<p>'.$get_row['name'].'<br/>'.$get_row['description'].'<br/><img src="'.$get_row['imagesrc'].'" /><br/>&pound;'.number_format($get_row['price'],2).'<a href="cart.php?add='.$get_row['id'].'">Add</a></p>';

The ' character defines a string literal when it is wrapped around a series of characters.
The . character is used for concatenating strings for output or storage.

like image 185
BenM Avatar answered Jun 17 '26 21:06

BenM


echo '<p>'.$get_row['name'].'<br/>'.$get_row['description'].'<br/><img src="'.$get_row['imagesrc'].'"><br/>&pound;'.number_format($get_row['price'],2).'<a href="cart.php?add='.$get_row['id'].'">Add</a></p>';
like image 26
abhshkdz Avatar answered Jun 17 '26 22:06

abhshkdz



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!