Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

insert an image into a php page from a mysql field id 1

Status
Not open for further replies.

mancroft

Programmer
Joined
Oct 26, 2002
Messages
267
Location
GB
I am creating a shopping cart and have a mysql database which contains a field called itemId

itemId is the id of an item in the form of a number 1 thru 50

There are some images on the server in the images folder named in the form:

1.png 2.png etc...

I wish to insert an image into the php page according to the item being viewed and need the php code to do so.

So that the HTML code ends up something like this:

<img src=&quot;images/3.png&quot;>

Something along the lines of

<img src=&quot;images/\$itemId\.png&quot;>

(which is probably wrong) perhaps.

Any ideas, please?
 
Just use echo or print to infuse the desired value:
Code:
# I assume $row holds the datarow from the table
echo '<img src=&quot;'.$row['itemId'].'.png&quot;>';

If your itemId is defined as a different var just replace $row['itemId'] with the appropriate variable.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top