Click to See Complete Forum and Search --> : displaying images not located in database


Hawkeye
04-07-2005, 09:52 AM
I need to display images that are located outside a DSN-less database connection in ASP. The old site was actually done in ASP.NET, but I want to do away with it as I am cheap.

At this point I can call up and display any and all of the database records. What I need is a way to combine the returned contents of a column with the path to the images and add on values for those that have multiple images.

For example: The database returns a value of say 9930120. The page should add that number to the path "say ...images/" add a value for + multiple images named with an a,b,c,d, e etc. and the file extention (.jpg) and then be able to display that/those image(s) in the table.

Here is the code:

<!-- #include file="connectionstring.asp" -->


<%
'variables
dim Conn, Connstring, Sql_Get, TheArray, Recordset

'database connection
Set Conn = Server.CreateObject("ADODB.Connection")

Conn.Provider = provider
Conn.ConnectionString = dbasepath
Conn.Open

'Sql statement
Sql_Get="SELECT * FROM table ORDER BY id"

Set Recordset = Conn.Execute(Sql_Get)

' get the recordset data in memory using getrows()
TheArray = RecordSet.Getrows

' Cleanup objects
Conn.Close
Set Conn = Nothing

Set RecordSet = Nothing
%>

<%
' start an HTML table to contain the results.

Response.write "<table border=1 width=500 cellpadding=3>"

' start the loop
For x = 0 to UBound(TheArray,2)

'format & write out the results
Response.write "<TR><TD><font size='1'>"
Response.Write "<b>Property Type</b> " & TheArray(16,x) & "<br>"
Response.Write "<b>#:</b> " & TheArray(1,x) & "<br>"
Response.Write "<b>Location:</b> " & TheArray(2,x) & "&nbsp;" & TheArray(10,x) & ",&nbsp;" & TheArray(11,x) & ",&nbsp;" & TheArray(14,x) & "&nbsp;County" & ",&nbsp;" & TheArray(12,x) & "<br>"
Response.Write "<b>ZipCode:</b> 0" & TheArray(3,x) & "<br>"
if InStr(UCase(TheArray(4,x)), "HTTP://") = 1 then TheArray(4,x) = "<a href='" & TheArray(4,x) & "'>" & TheArray(4,x) & "</a>"
Response.Write "<b>Link:</b> " & TheArray(4,x) & "<br>"
Response.Write "<b>List Price $:</b> " & TheArray(13,x) & "<br>"
Response.Write "</font></TD></TR>"


' next position
Next

' close table
Response.write "</TABLE>"
%>


The OLD site actually used ASP.NET and I don't know how this worked, but this appears to..

<a href='<%# databinder.eval(container.dataitem, "ML Number", "relistings.aspx?mls={0}")%>' target="relisting">
<IMG border="0" src='<%# checkPix(databinder.eval(container.dataitem, "ML Number"))%>' width="151" height="121"></a>

any help is welcome.

phpnovice
04-07-2005, 03:32 PM
For example: The database returns a value of say 9930120. The page should add that number to the path "say ...images/" add a value for + multiple images named with an a,b,c,d, e etc. and the file extention (.jpg) and then be able to display that/those image(s) in the table.
OK, but how do you want to lay out the images? ...and, how do you know how many images there are?
path = "/images/"
mult = Array("a", "b", "c", "d", "e")
ext = ".jpg"

<img src="<%= path & TheArray(1,x) & mult(0) & ext %>" border="0">

Hawkeye
04-08-2005, 08:14 AM
OK, but how do you want to lay out the images? ...and, how do you know how many images there are?
path = "/images/"
mult = Array("a", "b", "c", "d", "e")
ext = ".jpg"

<img src="<%= path & TheArray(1,x) & mult(0) & ext %>" border="0">

My bad. In the database is another column named PHO_CNT which list how many picutres there are corresponding with that row's ID.

I would like to display only the image a on the initial return and have each row link to a page displaying the whole lot of images.

Thanks for your inital help with the code sample. I am going to give that a little tryout.

-Hawkeye

phpnovice
04-08-2005, 08:21 AM
OK, I'll be here if you need more help. ;)

Hawkeye
04-08-2005, 09:08 AM
[another edit]
again, my bad. I can now get the actual image to display fine and I am going to work on the array to display all the images on a separate page.

I had recently update the database and NOT the image folder with the new images. <--true sign of slacking off

I tinkered around with your code, removed the array for ("a" "b" c") for now and attempted with Response.Write because <img src etc.> was displaying errors.

Response.ContentType = "image/jpeg"
Response.BinaryWrite (path & mls & mult & ext)

--Also, changed path to
path="<img src blah blah blah
and
added
Response.BinaryWrite (path & mls & mult & ext & ">")

phpnovice
04-08-2005, 11:17 AM
You should not be using BinaryWrite for this. You also should not have changed path. The IMG tag I posted previously was not intended to be inside your ASP code. It should have been in open HTML. However, to use Response.Write instead of the open HTML method I planned, you could change this:
<img src="<%= path & TheArray(1,x) & mult(0) & ext %>" border="0">
to this:
Response.Write "<img src=""" & path & TheArray(1,x) & mult(0) & ext & """ border=""0"">" & vbCrLf

Hawkeye
04-08-2005, 02:33 PM
Yeah, BinaryWrite does not work, that was my mistake.

It does work with my changes to your code though.
I should note for those who have similar problems...

'variables for the image path
path = "<img src=../images/IDX/"
mult = "a"
ext = ".jpg"
'remind system of file type
Response.ContentType = "image/jpeg"
'write the image, should be path+mls+mul+ext+closing bracket
Response.Write (path & MLS_NO & mult & ext & ">")

phpnovice
04-08-2005, 02:50 PM
You chould not be using this:

Response.ContentType = "image/jpeg"

if you are sending HTML. That is for when all you are sending is the actual binary content of the image itself -- i.e., no HTML at all. That is also when you would use Response.BinaryWrite.