PDA

For continued disscussion on this topic : get Picture from Database...



jasmine
08-17-2000, 01:42 PM
hi!:p
i have a drop down menu in the page, and a buton named = "show picture" the user clicked the button and new window will open with shows the picture of the selected item. the problem is this:
how do i get the picture from my access database???? the important notice: the picture of the selected item..
similar like :
if(Request.Form("pictureSelectField")) then
....picture is this...
End if
i hope u understand what i mean???
well please answer my question as soon as possible thanks :D

gzazJim
08-17-2000, 05:09 PM
jasmine,

A question for you - is the actual picture stored in the database? If so, that DB is going to get slow (not to mention HUUUUGE) really fast!

What I've done here is store a "pointer" to the picture in the database (http://www.website_addy.com/images/ipcturename.jpg), and then pulled that information from the database and formatted it in a table along with allthe other information about the picture (File size, description, etc...).

I think this would be a better solution for your problem! The select statement in your SQL would be tied to the selection made from the drop-down box. Something like this:

SELECT * from Data_Base_Table_Name WHERE form_select_info LIKE decsription_in_DB

I think this would work well. Good Luck!

Jim

jasmine
08-28-2000, 09:31 AM
well the picture stores in the DB. i changed the question like that: what if i have a table in my page like:
NAME ADRESS PICTURE
---- ------- -------
jasmine world :)

i want to get these information from the database and as u can see there is a picture field which includes the picture of the person :). i used:
<td><img src=<%=rS("picture")%>></td>
but did not work :)
i hope u understand what i mean...
thanks :P
c u

gzazJim
08-28-2000, 04:53 PM
Hi again jasmine,

I thought you had forgotten about us! :) Generally, it's easier to store a pointer to the picture in a database, because HTML can't reference the picture the way you have set up. HTML, in order to display a picture in the way you want, needs to know where the picture is stored on your server. If the picture itself if stored in the DB, you'll have to pull the picture out of the database in order to use it in your HTML.

This being said, the easiest way to reference the image would be to assign it a unique number in the database (001, 002, 003, ad nauseam...) and then call that number as part of the image name (image001.jpg, image002.jpg, image003.jpg, etc...). Try something like this for example:

<img src="images/image<%=rs("id")%>.jpg"

This way, you can also check for a value of "none" and create an image for that (imageNone.jpg - for example).

If you REALLY want to have the image stored IN the database, then you'll have to approach things in a MUCH more complicated and difficult way. You will not only have to assign the ASP code to point to the object, but you'll also have to tell the computer what KIND of an Object it is by setting it's MIME (Multipurpose Internet Mail Extensions)type. This MIME type tells the browser what kind of information to expect, and how to interpret it.

An example of setting a MIME-type is below:

<%Response.ContentType = "image/jpeg"%>

This tells the browser that this image is of the type JPEG (or jpg, etc...).

What you'll have to do, instead of referencing the file in the database directly, is reference a page which pulls the info OUT of the DB and puts it into the right format like so:

<img src="sqlbitmap.asp">

What happens here is then you write an ASP page that calls this data from the database and writes it to the page (save the below as "sqlbitmap.asp"):

<%
Response.Expires = 0 'This makes sure the data is the newest
Response.Buffer = TRUE ' Sends everything back to browser
Response.Clear 'Clear out the Response Object
Set conn = Server.CreateObject("ADODB.Connection")
conn.Open "DSN=Your_DSN_Info_Goes_Here"
Set rs = conn.Execute("SELECT image FROM table WHERE whatever")
Response.ContentType = "image/gif" ' Set the MIME type here
Response.BinaryWrite rs("image") 'Send the data to browser
rs.Close
Set rs=Nothing
conn.Close
Set conn = Nothing
Response.End ' Clear the Response Object
%>

Note that in this above example, you will absolutely NEED to know what KIND of data is stored in the DB. Otherwise the MIME type willbe just guesswork and will be absolutely worthless!

*Whew* That's a lot of coding, ain't it?

Good luck, and I hope this answered your question.

Jim

KodeKrash
08-29-2000, 02:02 AM
I would have to agree with Jim. Using blob/mime is inefficient, for a couple reasons.

1) larger databases
2) larger code base

Why type 25 lines of code for this -->

Set RS = Con.Execute( "INSERT INTO ImgTable (ImgURL) VALUES ('" & MyImgURL & "')" )
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Set RS = Con.Execute( "SELECT ImgURL FROM ImgTable" )
Response.Write( "<img src='" & RS( "ImgURL" ) & "'>" )

¿?¿?¿?¿?¿?¿?¿?¿?¿?¿?¿?¿?¿?¿?¿?¿?¿?¿?¿?¿?¿?¿?¿?¿?¿?¿?¿?¿?¿?

gzazJim
08-29-2000, 05:28 AM
KodeKrash,

Yeah - Things can quickly get to an unmanageable point when storing the actual files in a DB. Besides, it's easier and faster to store a pointer than it is to pull that BLOB data back out of a DB.

Thanks again for the help and support KK - it's appreciated, and nice to know my head's still on straight!!

Thanks!

Jim

jasmine
08-29-2000, 07:52 AM
thanks everyone espcially to gzazJim...
the codes u've given worked right but less efficient as u told. therefore i used easiest way u told before.... i excuse for tiring u that much :)
thanks thanks thanks thanks thanks.... :D

i'll be back.. :p

....
PS: close this thread pls :D

gzazJim
08-30-2000, 04:21 PM
Hi again Jasmine,

This Here thread is... Closed! Thanks again Jas, and hope we managed to help you out!

Good Luck,

Jim