使用php检索并在数据库中插入图像 [英] retrieve and insert image in database using php
问题描述
我正在插入和显示图像的各种数据。我正在一个restyrant网站上工作,我正在存储和显示项目及其图像。我创建了两个名为
food的表(id [PK], name,price,image,cat_id [FK])
category(cat_id [PK],cat_name)
1 - 我的任务是显示导航栏中的所有类别。
2 - 当我点击该类别时,它应该显示属于
3-insert类别的食物并更新信息
I am inserting and displaying various data with images.I am working on a restyrant website where I am storing and displaying the items along with their images.I have created two tables named food(id[P.K],name,price,image,cat_id[F.K]) category(cat_id[P.K],cat_name) 1-my task is to display the all categories in navigation bar. 2-when I click on the category it should display the food that comes under the category 3-insert and update the information
1-我的第一个任务是显示食品项目点击类别。这是代码,它工作正常
1-My first task was to display the food items onClicking the category.here is the code and it is working perfectly
<?php
$category=mysql_query("Select * from category",$connection);
while($category_name=mysql_fetch_array($category)) {
$category_name['cat_name'];
echo "<li><br><a href=\"show.php?category=". urlencode($category_name["cat_id"]) . "\">{$category_name["cat_name"]}</a></li>" . "<br />";
}
if(isset($_GET['category']))
{
$query="Select * from food where cat_id={$_GET['category']} ";
$result=mysql_query($query,$connection);
while($food_name=mysql_fetch_array($result))
{
echo $food_name["food_name"]. " Price is " . $food_name["food_price"];
它显示来自食物表的数据,这是我必须编写代码的地方为了显示图像。
it is displaying the data from the food table and this is place where I have to write the code in order to display images.
}
}
将图像存储在数据库中的任务完美无缺。
the task of storing the images in database is working perfectly.
推荐答案
在数据库中存储和检索图像非常缓慢而且困难。您可以为图像提供唯一ID(如时间戳)并将其保存到 images
文件夹中,也可以为此创建一个特殊文件夹。然后,在表中创建一个额外的列,并将id保存在相应的行中。您可以使用以下示例检索图像;
Storing and retrieving images in a database is really slow and difficult. You may give images a unique id (like timestamp) and save them into your images
folder or you may create a special folder for this. Then, make an extra column in your table and save the id in corresponding rows. You may retrieve images using the example below;
echo '<img src="images/'.$imageid.'.jpg">';
希望这有助于...... :)
Hope this helps...:)
这篇关于使用php检索并在数据库中插入图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!