-5

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.

Peon
  • 7,902
  • 7
  • 59
  • 100
user1533946
  • 9
  • 3
  • 4
  • 1
    Please stop duplicating questions only because you are not confident with the answers so far. [Dupe1](http://stackoverflow.com/q/11541357/367456) [Dupe2](http://stackoverflow.com/questions/11555424/retrieve-and-displaying-images-in-php-using-mysql) – hakre Jul 19 '12 at 07:02
  • I am new to this site and I had to add the additional code to my exixsting question.I did not see the edit option in that that's y I posted it again with the revised code – user1533946 Jul 19 '12 at 07:06
  • If you are new here, [the FAQ page](http://stackoverflow.com/faq) might be a good place to start. – spinningarrow Jul 19 '12 at 07:13
  • your code is difficult to read, please use a standard indentation... – Francesco Casula Jul 19 '12 at 08:12

2 Answers2

2

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

Alfred
  • 21,058
  • 61
  • 167
  • 249
  • I have uploaded the insertion of image code plz have a look at it and tell me where I have to use the your code – user1533946 Jul 19 '12 at 07:03
1

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

Bhuvan Rikka
  • 2,683
  • 1
  • 17
  • 27