简体   繁体   English

PHP&MySQL-如何在查询结果中添加图片?

[英]PHP & MySQL - How to add images to query result?

I am creating a car rental system for school and I was wondering how can I display the correct image of the car for each result the user gets when searching the database. 我正在创建学校的租车系统,我想知道如何为用户在搜索数据库时获得的每个结果显示正确的汽车图像。 For example: 例如:

A user wants to see all Toyotas in Oslo with a picture of the car in the result. 用户希望在结果中看到奥斯陆的所有丰田汽车以及汽车的图片。 The picture name is eg 'toyotaavensis.jpg' 图片名称例如是“ toyotaavensis.jpg”

Now what I Want is the image of the Toyota Avensis display in the div that contains the info about that specific car. 现在,我想要的是div中Toyota Avensis显示的图像,其中包含有关该特定汽车的信息。

I have the images stored on my schools FTP server and I get the info from a database 我将图像存储在学校的FTP服务器上,并且从数据库中获取信息

I manage to get the search function working with all the info and such. 我设法使搜索功能可以处理所有信息等。 I'm just stuck on the images 我只是停留在图像上

If you can find the image name from the DB, then you just need to add that after the PATH of the image. 如果可以从数据库中找到映像名称,则只需在映像的PATH之后添加该名称。 For eg. 例如。 if the name returned from DB is: toyotaavensis.jpg and the PATH where the image is located is (related to the page on which it is to be added): images/ then you just need have the path on your page for image as: images/{DB-result-for-image} 如果从数据库返回的名称是: toyotaavensis.jpg并且图像所在的路径是(与要添加images/的页面有关): images/那么您只需要在图像上的路径为: images/{DB-result-for-image}

Add a column "picture" to your database and insert the name of the associated picture everytime you add a new entity to the database. 每次将新实体添加到数据库时,在数据库中添加一列“图片”,并插入关联图片的名称。 You may name the pictures for a pattern. 您可以为图片命名图案。 Then, get the associated picture and display it with HTML. 然后,获取关联的图片并使用HTML进行显示。

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

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