retrieve and insert image in database using php [c

2019-03-07 07:32发布

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-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.

2条回答
冷血范
2楼-- · 2019-03-07 08:19

Storing images in database is not a good practise. In this case, you have to use <img> tag to retrieve those images

查看更多
够拽才男人
3楼-- · 2019-03-07 08:21

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...:)

查看更多
登录 后发表回答