Important alert: (current site time 7/16/2013 12:00:22 AM EDT)
 

article

Creating an Online Photo Album

Email
Submitted on: 7/21/2000 11:03:22 AM
By: Christopher Miller  
Level: Intermediate
User Rating: By 4 Users
Compatibility: ASP (Active Server Pages), HTML
Views: 43618
 
     Quick example of Creating an Online Photo Album using a database back-end.

 
 
Terms of Agreement:   
By using this article, you agree to the following terms...   
  1. You may use this article in your own programs (and may compile it into a program and distribute it in compiled format for languages that allow it) freely and with no charge.
  2. You MAY NOT redistribute this article (for example to a web site) without written permission from the original author. Failure to do so is a violation of copyright laws.   
  3. You may link to this article from another website, but ONLY if it is not wrapped in a frame. 
  4. You will abide by any additional copyright restrictions which the author may have placed in the article or article's description.
				Creating an Online Photo Album
by Ritchie Macapinlac

Useful Links

·         A working copy of this application.(http://www.boogienet.com/photoalbum)

·         JavaScript Tutorial (http://hotwired.lycos.com/webmonkey/programming/javascript/tutorials/tutorial1.html)

The Application Description

The whole backbone of the application is the database, which maintains a set of links to images and the comments to the images. The database will have 4 fields: pic_id, thumbnail, pic_url, and comment. Each record will represent 1 picture that the database maintains. Each set of pictures has 2 physical files (thumbnail and the actual picture url).

There are 2 asp pages to the whole application. One page, will be the index of the pictures and the second will display the actual picture. We use javascript to open the actual picture up from the index page, passing it the actual address of the picture.

The Database

The database only maintains a set of links and does NOT store images in the fields themselves. There are 4 fields in the database:

1.       Pic_id, is the unique identifier of the picture and how the pictures are ordered on the index page. (number, also the primary key)

2.       The thumbnail field is the url of the thumbnail of the picture in the index page. (text)

3.       The pic_url page maintains the links to the actual picture. This will be passed from the index page to the display page. (text)

4.       The pic_description, is used to have a comment associated with every picture. (memo)

The Index Page

The index page is a combination server-side asp (to process the database) and client-side javascript (to pass the url to the display page).

The code of the page looks like this:

 

<html>

<head>

<title>Album Index Page</title>

<script language=”JavaScript”>

function OpenPic(url){

//format url of the picture

var newwindow = "pic.asp?pic_url=" + escape(pic_url);

//properties of the new window

var window_properties = "title=false,width=400,height=400";

//open the window

var PicWindow = window.open(newwindow,"Album",window_properties);

};

</script>

</head>

 

<body>

 

<%

Dim dbConnection, rsRecordSet, strSQL

 

StrSQL = “SELECT * FROM tblAlbum ORDER BY pic_id ASC”

 

Set dbConnection = Server.CreateObject(“ADODB.Connection”)

Set rsRecordSet = Server.CreateObject(“ADODB.RecordSet”)

‘open the database with the connection string (dsn or dsn-less) – replace “connection_string with your database connection string

DbConnection.Open “connection_string”

RsReocrdSet.Open strSQL, dbConnection

If not(rsRecordSet.EOF and rsRecordSet.BOF) then

RsRecordSet.MoveFirst

While not rsRecordSet.EOF

%>

<a href=”javascript:OpenPic(‘<%Response.Write(rsRecordSet.Fields.Item(“pic_url”))%>’)”>

<img src=”<%Response.Write(rsRecordSet.Fields.Item(“thumbnail”))%>”></a>

<br>

<%Response.Write(rsRecordSet.Fields.Item(“pic_description”))%>

<br><br>

<%

RsRecordSet.MoveNext

wend

End if

RsRecordSet.Close

DbConnection.Close

Set rsRecordSet = Nothing

Set dbConnection = Nothing

%>

</body>

</html>

 

Ok, simple databases query page, but here’s the cool part. In the “<a href” tag, it calls the javascript function to open the new window and pass the url to the display page.

The Display Page

The only thing the display page does is display a picture url. The picture url is passed through the querystring calling this page. Of course there are 2 ways to do this, one is javascript and the other of course is server-side vbscript. To keep things simple and consistent, we’ll learn the “easier” vbscript first.

 

<html>

<head>

<title>Display Picture</title>

</head>

 

<body>

<center>

<img src=”<%Response.Write(Request.QueryString(“pic_url”))%>”>

<br><br>

<form>

<input type=”Button” OnClick=”self.close();” value=”Close Window”>

</form>

</center>

</body>

</head>

</html>

That’s all there is to that page.


Other 3 submission(s) by this author

 


Report Bad Submission
Use this form to tell us if this entry should be deleted (i.e contains no code, is a virus, etc.).
This submission should be removed because:

Your Vote

What do you think of this article (in the Intermediate category)?
(The article with your highest vote will win this month's coding contest!)
Excellent  Good  Average  Below Average  Poor (See voting log ...)
 

Other User Comments
1/12/2001 11:31:35 PMPablo Gonzalez

Hey, I got a error in the JavaScript code, because it isnīt work, so I fixed it:

On the line: var newwindow = "/pic.asp?pic_url=" + escape(pic_url). Change "escape(pic_url)" to "escape(url)"

But It is a great work. It help me a lot
(If this comment was disrespectful, please report it.)

 
1/6/2002 7:39:54 PMmoon

This code is extremely buggy - There are at least 10 - 20 seemingly
(If this comment was disrespectful, please report it.)

 
1/6/2002 7:45:47 PMmoon

This code is extremely buggy - There are at least 10 - 20 seemingly "intentional" bugs. Why would the author sabotage his own work? Maybe because he doesn't want us to have a working album. If you don't believe me, please use his code and attempt to create a working ASP/album. Please try! I'm not sure how this code won "Code of the Month" - that sure doesn't say much for this website.


(If this comment was disrespectful, please report it.)

 
6/15/2002 1:59:48 PMphotoalbum

online
(If this comment was disrespectful, please report it.)

 
1/2/2003 5:43:26 AM

how can i down load the code...copy and past is not working
(If this comment was disrespectful, please report it.)

 
3/5/2003 11:48:02 AM

Doesn't seem to work as written but it pointed me in the right direction. If you view the source on the "working copy" you'll see everything is hard-coded, there's no db lookup on the sample page.
(If this comment was disrespectful, please report it.)

 
4/24/2003 10:19:11 AM

u have just made my day, i have my uni project to hand in in a week n been having real problems displayin images from my database but just one of ur lines of code sorted it, u deserve a pint :P

(If this comment was disrespectful, please report it.)

 
5/22/2003 7:22:32 PMStevelee

I checked this script's java-script,
it's asp script,I don't know how to
use from web-pager...??
(If this comment was disrespectful, please report it.)

 
4/18/2006 12:34:41 AMraaz

good codes
(If this comment was disrespectful, please report it.)

 

Add Your Feedback
Your feedback will be posted below and an email sent to the author. Please remember that the author was kind enough to share this with you, so any criticisms must be stated politely, or they will be deleted. (For feedback not related to this particular article, please click here instead.)
 

To post feedback, first please login.