Jump to content
Larry Ullman's Book Forums

Images In The Database


Recommended Posts

On page 194, Larry gives us code to populate our databases. For example,

 

INSERT INTO 'non_coffee_categories` (`category`, `description`, `image`) VALUES
('Edibles', 'A wonderful assortment of goodies to eat...', 'goodies.jpg')

 

In the paragraph below the code,it also says the images should be placed in the products directory.

 

I executed these commands and, indeed, when I check the database with PhpMyAdmin, I can see the records, but I don`t understand something about the image.

 

Is there an actual image in the database, or is it merely a record of the image?

 

If there is an actual image in the database, how did it get there? The SQL quoted above says to put an image into the database, but I don`t understand how it actually gets the physical image (from where?) and puts it into the database, as there is nothing in the SQL that specifies where the image comes from etc.

 

Note, I am searching around in PHP my admin but I don`t know how to check if it`s an actual image or merely a record of an image that`s being associated with the other content.

 

I`m guessing that in the database, it is merely a record of an image that is somehow associated with the images that are placed in the products folder, as Larry specifies, but please confirm if you can. Also, if that`s correct, why is it necessary to create a mere record in the database and how (i.e. what script) does it get associated with the image in the products folder.

 

Thanks

Link to comment
Share on other sites

Sorry, as I don't have the book handy at the moment, but generally, you don't put actual images in a database, as they're too big, but instead provide a path to the image, etc. By using the path, you can quickly and easily load the actual image, as necessary.

  • Upvote 1
Link to comment
Share on other sites

Thanks Hartley. I am unfortunately still mystified.

 

You say that you generally put the path to the image, but in this code, Larry doesn`t put the path (as far as I can tell). Just a name of the image (unless it is of course the actual image)

 

Can anyone explain, if it is just the name of the image, what is the value of putting only the name into the database, and where, in this application, does it connect to the actual image?

 

INSERT INTO 'non_coffee_categories` (`category`, `description`, `image`) VALUES 
('Edibles', 'A wonderful assortment of goodies to eat...', 'goodies.jpg')

Link to comment
Share on other sites

Page 208 perhaps?I've only skimmed the pages but the same principles apply. You store either the full path or a filename and then work your while loop in order to generate the relative or absolute path to the image. If you look you'll see something like:

Src="/products/' . row['image'] . '". All this is doing is giving most of the file location hardcoded into the while loop and your just looping over the image column to swap in the correct filename.jpg for the product.

 

Hope that helps

Link to comment
Share on other sites

To understand this in more detail I would recommend going through the first website example again and focus on the PDF upload part of the site.

 

I learn much better by example myself and that part of the book if you go through it until you understand it, it really goes through this really really well. Even though it is a PDF document the same exact thing works for ANY file format.

Link to comment
Share on other sites

 Share

×
×
  • Create New...