开发者

How insert image while echoing according to category?

开发者 https://www.devze.com 2023-03-13 21:16 出处:网络
I have a registration form and that goes to database. Some categories are there to select in the registration form. While registering he want to select one category mandatory. For example he select \"

I have a registration form and that goes to database. Some categories are there to select in the registration form. While registering he want to select one category mandatory. For example he select "travel". And this category will save into database under category. And there is a page to echo these t开发者_Go百科hings. While echoing I want to display an image according to the category. If "travel" one particular image, if "political" another image etc.etc... Please help. These images want to store inside database or local directory?


The easiest way is to have a folder that will contain all your images and in the category table your structure it like this

Id | Title  | Image
1  | Travel | travel.jpg

than when you want to echo the image just create an img tag and use the name from the databse

<img src="/img/categories/<?php echo $categoryName ?>" />

HTH


Store the images on file system and not in the database. One possible option to display images could be to name your images according to the category IDs present in the database. so if the categoryID for "travel" is '1' then rename the "travel.jpg" image to "1.jpg" and so on. Then using php display that category image.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号