Forum Moderators: open
I created a new database with a table named (PHOTO)
in the table the categories listed are (id) and (source).
ID's range from 0-41, and an example of what's in my source column is [www10.brinkster.com...]
Ive even tried not using the full URL to no success.
I'm creating a photo gallery that will host 42 pictures and a single page. I need to know how to get an image to appear from text written in a database . I have a page called photographs.asp that has an images named
<img src="photos.asp?id=0">
all the way down to
<img src="photos.asp?id=41">
I need help on getting the images from photos.asp to photographs.asp
Here's the source for photos.asp:
-----------------------------------------------------------
<% OPTION EXPLICIT %>
<%
'On Error Resume Next
Dim sql
Dim rs
Dim oconn
Dim sConnString
Dim strID
'Get querystring parameter
strID = Request("id")
If strID = "" Then strID = 0
'oConn.Open(sConnString)
'Instantiate Objects
Set oconn = Server.CreateObject("ADODB.Connection")
sConnString = "DRIVER={Microsoft Access Driver (*.mdb)};" & _
"DBQ=" & Server.MapPath("\jfhs\db\web.mdb") & ";"
Set rs = Server.CreateObject("ADODB.Recordset")
'Open connection
oConn.Open(sConnString)
'Application("aspdb_ConnectionString")
'Get the specific image based on the ID passed in a querystring
sql = "SELECT f.source " & _
" FROM photo f " & _
" WHERE f.id = " & strID
rs.Open sql, oconn
'If no record found, end.
if rs.eof then
rs.Close
Response.End
end if
'Display the contents of the record as an image
Response.ContentType = "image/jpeg"
'----------!Don't know what to use here!----------------
'Response.BinaryWrite(rs("source"))
'Response.Write ("<img src=""" & rs("source") & """ >")
'Response.Write(source)
'---------------------------END-----------------------------
'Clean up
rs.Close
oconn.Close
set rs = Nothing
set oconn = Nothing
%>
Thanks so much,
Brandon Meyer
'----------!Don't know what to use here!----------------'Response.BinaryWrite(rs("source"))
'Response.Write ("<img src=""" & rs("source") & """ >")
'Response.Write(source)
'---------------------------END-----------------------------
Just use:
<img src="<%=rs("source")%>">
Response.ContentType = "image/jpeg"
Not needed
Everything about the image code is dynamic:
<a href="<%=rs("href")%>"><img src="<%=rs("source")%>" alt="<%=rs("alt")%>" width="<%=rs("width")%>" height="<%=rs("height")%>" border="0"> </a>
Here is the script for test.asp
It properly displays the image url when I open
"test.asp?id=0"
My problem is, is that when I try to use the image in a seperate page, <img src="test.asp?id=0">, it fails to display the image. I'm trying to get the image to appear on seperate pages, not test.asp. It only serves as an interface.
Thanks again
<%
Dim sql
Dim rs
Dim oconn
Dim sConnString
Dim strID
'Get querystring parameter
strID = Request("id")
If strID = "" Then strID = 0
'oConn.Open(sConnString)
'Instantiate Objects
Set oconn = Server.CreateObject("ADODB.Connection")
sConnString = "DRIVER={Microsoft Access Driver (*.mdb)};" & _
"DBQ=" & Server.MapPath("\jfhs\db\web.mdb") & ";"
Set rs = Server.CreateObject("ADODB.Recordset")
'Open connection
oConn.Open(sConnString)
'Application("aspdb_ConnectionString")
'Get the specific image based on the ID passed in a querystring
sql = "SELECT f.source " & _
" FROM photo f " & _
" WHERE f.id = " & strID
rs.Open sql, oconn
'If no record found, end.
if rs.eof then
rs.Close
Response.End
end if
'Display the contents of the record as an image
'Response.BinaryWrite(rs("source"))
'Response.Write ("<img src=""" & rs("source") & """ >")
Response.Write rs("source")
'Clean up
rs.Close
oconn.Close
set rs = nothing
set oconn = Nothing
%>
with response
.Expires=0
.Expires=-1
.ExpiresAbsolute = #1/1/1980#
.AddHeader "Pragma", "no-cache"
.ContentType = "image/jpeg"
end with
Dim oStream
set oStream = server.createobject("ADODB.Stream")
oStream.Type = 1
oStream.Open
oStream.LoadFromFile rs("source")
response.binarywrite oStream.read
set oStream=nothing
response.End
this way you can use the .asp page in the <img> tag and it will embed it in the page.
I'm going to have two pages and a database.
Photograph.asp - will display an image based on ID #
dm.asp - will open the database and extract the image URL
web.mdb - contains records of ID# and Image URL
So basically:
Photograph.asp requests the image url from db.asp
<img src="db.asp?id=0">
db.asp opens the database and extracts record 0 from the database.
Request = Photograph.asp -> db.asp -> web.db
When I open db.asp, the image url shows up, I can also make the image appear using response.write
I've tried the line of code that txbakers and foosion wrote, but still not working. How do I get an image tag in photograph.asp to recognize the url in db.asp?
Thanks again,
Brandon
'Get querystring parameter
strID = Request.QueryString("id")
response.write(strID)
If strID = "" Then strID = 0
Now for the displaying of the images:
'Get the specific image based on the ID passed in a querystring
sql = "SELECT f.source FROM photo f WHERE f.id =" & strID
rs.Open sql, oconn
While Not rs.EOF
Response.Write("<img src='" & rs("photourl") & "'>")
rs.MoveNext
Wend
rs.Close
Response.End
end if
This should work.
Mac
I've tried the line of code that txbakers and foosion wrote, but still not working. How do I get an image tag in photograph.asp to recognize the url in db.asp?
Excuse my butting in, but I can't see this explicitly mentioned anywhere: The majority of these solutions look like code for photograph.asp, not db.asp/test.asp/photo.asp.
Unless you're doing watermarking or image resizing, there's no obvious reason to use a seperate page to retrieve the URL from the database. You can't use text in the src attribute of an image, which is what you appear to be producing in db.asp. That's probably why using db.asp?id=0 as the src attribute isn't working for you.
hth,
g.
Here's what you're looking for. Don't call the image page up using the <img src=""> tag, use an <iframe src=""></iframe> instead. you will have to specify the height and width of the iframe to get it to fit every time, but I think that is what you are looking for.
Good luck getting the cookies set up to verify that the images are loading from the page and not from a direct visit. If you are trying to do this for multiple images per page it can be tricky.
Good luck!