简体   繁体   English

如何根据数据库中的数据回显图像? (Mysql, PHP)

[英]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.你错过了封闭的 img 标签。 try this way...and what about ucwords, to be sure first check result before using it.试试这种方式......还有ucwords呢,确保在使用之前先检查结果。

 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在服务器中设置相对于您的 php 脚本的图像源

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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