简体   繁体   中英

How to echo images based on data from database? (Mysql, Php)

I am doing some sort of online storefront and each item has a corresponding image in the database. i need to echo the image of that specific item, how do i do it? This is what i've done, But it doesn't seem to work:

<?php
  $prebuy = "SELECT lot_image FROM lots WHERE  lot_id= '$lot_id'";
  $prebuyres = mysqli_query($mysqli, $prebuy) or die(mysqli_error($mysqli));
  $lot_name = mysqli_fetch_assoc($prebuyres);
?>
<img src="C:\\xampp\htdocs\storefront\img\<?php  echo ucwords($lot_name['lot_image']); ?>" 

The image does not appear but there is no error either. What am i doing wrong? Please, help if you can.

Thanks in advance!

You missed enclosing img tag. try this way...and what about ucwords, to be sure first check result before using it.

 echo ucwords($lot_name['lot_image']); 

<img src="C:\\xampp\htdocs\storefront\img\<?=ucwords($lot_name['lot_image'])?>"/> 

Edit:
set you image source relative to your php script in server like

   <img src="img/<?=ucwords($lot_name['lot_image']);?>"/>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM