Access Help

Soldato
Joined
30 Nov 2005
Posts
3,084
Location
London
I am creating a small online shop in PHP and Access.

The Access database will be used to store the products.

My only problem is the images for the products, how do I link to images in Access so when shown on the php page it will show the appropriate images for each product.

I hope this makes some sense.

James
 
first off if you're expecting a lot of visitors it may be wise to use a better suited DBMS such as MySQL as Access has limited connections.

To answer your question there are 2 ways i can think of:

1. Store the image inside the DB as a binary object. You can do this in MS SQL Server as a BLOB but im not sure about Access

2. Store the relative URL of the image in the database and just make sure that the image is in the location specified. This will obviously keep your database size down but you have to make extra efforts to ensure that the URLs remain correct.
 
It's only for a very small example shop.

I was hoping to do Step 2, but can't for the life of me work out how. Would it be stored as a hyperlink in the Table or something else?
 
Hello,

You can store images in the Access DB using the Image datatype.

As SoapSurgeon said,
If you didn't want to do this, you save the ID and just the filename of the image in the database. Then when you generate the HTML for the page, the HTML will call to the correct image.

Need to watch out for duplicate filenames etc, but this is it in simplest forms.
 
Ok. Without trying to patronise you I'll walk through the basics...

To display an image in HTML you use the <img src="images/myimage.jpg" alt="My Image" /> tag.

As you can see the src part tells you where the image is located (in the images folder and called 'myimage.jpg'. All you want to do is load the image url from a database, probably using php.

so in your database you could have something like the following:

Code:
ProductID, ProductName, ProductPrice, ProductImage
1        ,'Nokia N73' , 179.99      , 'images/phones/nokian73.jpg'

Then you can load the url into a variable in php and replace the hard coded example above with the variable.

Hope that makes sense!

disclaimer: I haven't coded in aaaaages so all this is from memory and may not be 100% accurate but im sure someone will correct me if im wrong
 
Thanks for the help so far.

It's just in Access I can't quite work out how to store the image path. What DataType would I set it to in the Table?
 
databasebp2.jpg


Something like the above?
 
JamesU2005 said:

Something like the above?[/QUOTE]
exactly like that. You will have to be careful that the text in the productImage field is a valid URL to an image otherwise you will get errors in your web page.

A handy tip is to catch any errors in your code and display a generic 'Image not found' image in its place.
 
JamesU2005 said:
Thanks for your help.

I will store it just like the structure in your example 'images/phones/nokian73.jpg',

that URL implies that there is a folder called images in the same directory as the web page which contains a folder called phones which contains an image called nokian73.jpg. As long as all that is true then it will work.

although dont call all your images nokian73.jpg ;)
 
Back
Top Bottom