简体   繁体   English

从数据库中将图像插入 html 表中

[英]insert image in html table from database

I am trying to display my images in a HTML table but for some reason they just won't show up.我试图在 HTML 表中显示我的图像,但由于某种原因它们不会显示。

The images are located in a separate folder called 'images' and the image name is stored in my database as a varchar named eg, filename.jpg这些图像位于一个名为“images”的单独文件夹中,图像名称作为 varchar 存储在我的数据库中,例如 filename.jpg

In my overview page I use this as my code:在我的概述页面中,我使用它作为我的代码:

<!DOCTYPE html>
<html lang="en">
<body>
    <table>
    <?php
        foreach ($objectname as $key) {
            echo '<tr><td><img src="images/' . $key->getImage() . '"></td></tr>';
        }
    ?>
    </table>
</body>
</html>

Hoping someone here can point me in the right direction:) thanks!!希望这里有人能指出我正确的方向:) 谢谢!

You should first print print_r ($objectname), check if it comes with data and what its attributes are to see which one you need to occupy.你应该先打印print_r($objectname),检查它是否带有数据以及它的属性是什么,看看你需要占用哪个。 Second the $ key->getImage() getImage () = function () you are calling a function.其次 $ key->getImage() getImage () = function () 你调用的是 function。

I think you should change the getImage() function in your html to the name of the field in the database as follows: $key->getImage() to $key->Image_field_name_in_the_database我认为您应该将 html 中的 getImage() function 更改为数据库中字段的名称,如下所示: $key->getImage()$key->Image_field_name_in_the_database

Because the name of the image (eg: filename.jpg) is saved in a field of a table in your database.因为图像的名称(例如:filename.jpg)保存在数据库表的字段中。 Image_field_name_in_the_database will be the name of the field that contains the name of the image in the database. Image_field_name_in_the_database将是包含数据库中图像名称的字段的名称。

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

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