Jump to content
Larry Ullman's Book Forums

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

Share this post


Link to post
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

Share this post


Link to post
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')

Share this post


Link to post
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

Share this post


Link to post
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.

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...

×
×
  • Create New...