Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

load photos from a database

Status
Not open for further replies.

lizzi

Technical User
Feb 12, 2004
45
SE
Hi
I wounder if ther´s a easy way to load photos from a database (access) with asp. I want to create a site with a lots of pictures and they should load from the database. The problems is where should I start? I now a little about asp, and how to create the database, but I want to use several categories for the photos. Where should I start, perhaps ther´s a tutorial somewhere who could help me?

/Lizzi
 
don't try to load photos from the database especially not with access, the processing required puts a huge load onto the server and slows everything down.

Article on storing binary data

The best way is to simply to store the url to the photo in the db then use this to display the image on the page.



Chris.

Indifference will be the downfall of mankind, but who cares?
 
Chris is absolutely right.

Storing images in a db is called BLOB and is most unwise with access.

As well as storing the URL consider other info with the image e.g. alt tag info, photographer, whatever your little heart desires.

Steve Davis
hey.you@hahaha.com.au

Me? I can't even spell ASP!
 
Thanks, but I don´t want to use asp.net cant this be done in ordinary asp. I feel it´s easier for me to start with.

/Lizzi
 
Err...no one mentiond .Net that I noticed. Simply have a field that is of type text, place the URL of the image in there, then when you display it output the contents of that field into the src field for an img tag. (still confused about the .Net reference)

-T

[sub]01000111 01101111 01110100 00100000 01000011 01101111 01100110 01100110 01100101 01100101 00111111[/sub]
The never-completed website:
 
standard asp is not a problem,
I'm in the process of putting a categorised gallery together primarily to focus on high SE visibility and many of the scripts you see around aren't capable of setting all the information needed.
A categorised photo db only needs two tables, one for the cats and associated text and one for the photo urls and associated text and a Microbe pointed out a lot of information can be in there.

This is in ASP with a MySQL backend.
(and not a table tag in sight!)



Chris.

Indifference will be the downfall of mankind, but who cares?
 
Thanks

ChrisHirst -> Your gallery is the way I want it :) I now how to put the link in the database, and how to publish them, but how do you link to a larger image? Do you have different links in the database? And you have different categories in the database to?

Lizzi
 
You have two references in the table, one for the thumbnail and one for the full size image.

Then when you write the page, put the large pic ref into the anchor:

response.write "<a href='images\" & rst.fields("bigpic") & ".jpg'>"
<img src='images\" & rst.fields("thumbnail") & ".jpg'>"
</a>

(Because I always give my thumbnails the same name stem but append "-th", I actually only use one field, which makes it even easier to enter the info into the database.)

You include ALT tag text the same way.
 
Sorry, sloppy formatting:
Code:
response.write "<a href='images\" & rst.fields("bigpic") & ".jpg'>" & _
"<img src='images\" & rst.fields("thumbnail") & ".jpg'>" & _
"</a>"
 
No categories as yet, just a work in progress (amongst other things) but it's not difficult to categorise the gallery pages all it will need is a parameter passing with the cat no and adding into the SQL (... AND WHERE cat_id = " & cat & ...)

This is the script that displays the thumbnail and sets up the links. I name my thumbnails with '_t' added to the name and store the type in a separate field and concantenate the fields into a string.
the linked page 'pics.asp' gets the ID number from the query string and reads the details out of the db including (if and when set) page title, captions, plus any text about the picture.
some of the variables I use are dimmmed and defined either in the calling page or in the site config file. This script is in an included functions file, that way it's use is not limited just to the pic gallery.

Code:
function ShowPic(ID,bCap)
' function to get image path and name from db and display thumbnail
' with link to main image 
'ID is the picture number in the db 
' bCap is true or false and determines if caption is shown
dim strPicTN ' set thumbnail name
dim strPicName
dim strCaption
dim strPicAlt
dim strPageHeader

dim db


strGallerySQL = "Select  * FROM " & GalleryTable & " WHERE id = " & ID & " ;"

Set objConn = Server.CreateObject("ADODB.Connection")
objConn.Open strSQLConnString 
Set objRS = Server.CreateObject("ADODB.Recordset")
objRS.CursorLocation = adUseClient
objRS.Open strGallerySQL, objConn, adOpenStatic, adLockReadOnly, adCmdText

if objRS.RecordCount <> 0 then
strPicAlt = objRS.Fields("pic_alt")
strCaption= objRS.Fields("pic_caption")
strPicTN = "/images/" & objRS.Fields("pic_path") & "/" & objRS.Fields("pic_name") & "_t." & objRS.Fields("pic_type")
strPicName = "/images/" & objRS.Fields("pic_path") & "/" & objRS.Fields("pic_name") & "." & objRS.Fields("pic_type")

end if
response.write "<a href='/pics.asp?pic=" & ID & "' title='" & strPicAlt & "'>"
response.write "<img src='" & strPicTN & "' alt='" & strPicAlt & "' title='" & strPicAlt & "'>"
response.write "</a>"
if bCap then 
response.write "<a href='/pics.asp?pic=" & ID & "' title='" & strPicAlt & "'>"
response.write strCaption
response.write "</a>"
'response.write "<br>"
end if

objRS.Close
Set objRS = Nothing
objConn.Close
Set objConn = Nothing

end function

it's probably not using the most efficient code and one day I'll tidy it up!

Have Fun [thumbsup]



Chris.

Indifference will be the downfall of mankind, but who cares?
 
Thanks alot to all of you for your kind help,

I´l try and see if I fix ít. :)

/Lizzi
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top