Click to See Complete Forum and Search --> : ASP Classifieds -- displaying the images
dthatsme33
03-11-2010, 12:51 PM
I am displaying our newspaper classified listings online using ASP and Access. I am importing an XML file that is run on a daily basis that pulls all of the ads.
I got the ads to display just fine but I'm not sure how to get the images to appear. I have them in a field called IMAGE1 with a URL for the image which is stored in a folder on our server. There is another field called image1Typ that contains the type of image it is: LOGO, GRAPHIC OR PHOTO.
Basically I want the image to display if there is one for the ad. If it is a logo I want it to be on the top of the ad. If it's a photo or graphic it will be to the left of the ad.
I'm not sure how to code this. I figure that I need an if statement -- if there is an image display it; if it's a logo put it here, if it's a graphic or photo put it here. I have no idea how to code this so any help would be appreciated.
Thanks!
yamaharuss
03-11-2010, 02:26 PM
If rs("IMAGE1") <> "" then
<img src="<%=rs("IMAGE1")%>">
dthatsme33
03-11-2010, 02:57 PM
If rs("IMAGE1") <> "" then
<img src="<%=rs("IMAGE1")%>">
Am I supposed to add something here? Sorry, I'm a code newbie. :o
yamaharuss
03-11-2010, 02:58 PM
Then you need to post your code.
dthatsme33
03-11-2010, 03:19 PM
Here's what I have so far.
In the head:
<%
Dim rsArticles
Dim rsArticles_cmd
Dim rsArticles_numRows
Set rsArticles_cmd = Server.CreateObject ("ADODB.Command")
rsArticles_cmd.ActiveConnection = MM_Classifieds_STRING
rsArticles_cmd.CommandText = "SELECT * FROM AD WHERE CLASS_NUMBER = '99' ORDER BY START_DATE ASC"
rsArticles_cmd.Prepared = true
Set rsArticles = rsArticles_cmd.Execute
rsArticles_numRows = 0
%>
<%
Dim Repeat1__numRows
Dim Repeat1__index
Repeat1__numRows = -1
Repeat1__index = 0
rsArticles_numRows = rsArticles_numRows + Repeat1__numRows
%>
This is where the ads will display in the body:
<img src="<%=(rsArticles.Fields.Item("IMAGE1").Value)%>" width="32" height="32" /> <%=(rsArticles.Fields.Item("AD_TEXT").Value)%>
I have an image pulling from the database but when there isn't one I need it to be nothing. And of course displaying the image in a certain place depending on the type in the image1Typ field.
yamaharuss
03-11-2010, 03:22 PM
<%
strImage = rsArticles.Fields.Item("IMAGE1").Value
If strImage <> "" then
%>
<img src="<%=strImage%>" width="32" height="32" /> <%=(rsArticles.Fields.Item("AD_TEXT").Value)%>
<%End If%>
dthatsme33
03-12-2010, 08:12 AM
I'm still getting blank images appearing.
http://ads.butlereagle.com/Classifieds/search/articles.asp
Is there something else that's supposed to go here?
If strImage <> "" then
yamaharuss
03-12-2010, 09:03 AM
Are they blank or are the fields NULL?
If you have NULL fields then simply change the code to:
<%
strImage = rsArticles.Fields.Item("IMAGE1").Value & ""
If strImage <> "" then
%>
<img src="<%=strImage%>" width="32" height="32" /> <%=(rsArticles.Fields.Item("AD_TEXT").Value)%>
<%End If%>
yamaharuss
03-12-2010, 09:08 AM
Ya know, I looked at your link and didn't see any images at all.
dthatsme33
03-12-2010, 11:02 AM
Sorry, I was making changes to the database. I'm having issues with the XML file pulling into Access correctly.
The fields are Null. I will input that code and see what happens. Thank you!
dthatsme33
05-20-2010, 10:48 AM
I am revisiting this issue. I had to take a break to work on another more pressing one.
I'm not getting this to work with the code you provided.
<%
strImage = rsArticles.Fields.Item("IMAGE1").Value
If strImage <> "" then
%>
<img src="<%=strImage%>" width="32" height="32" /> <%=(rsArticles.Fields.Item("AD_TEXT").Value)%>
<%End If%>
I just get a red box. The image appears using this code:
<img src="<%=(rsArticles.Fields.Item("IMAGE1").Value)%>" />
See previous posts for my header code.
Thanks!
yamaharuss
05-20-2010, 11:11 AM
The next obvious question is "what is the image code output?" is it formatted correctly? does the image exist? do you need to add a directory??
dthatsme33
05-20-2010, 11:17 AM
Everything is fine with the image. It is in the database as a URL. I tested it and it appears.
This is the page I'm working on. (http://ads.butlereagle.com/Classifieds/search/articles.asp)
yamaharuss
05-20-2010, 02:01 PM
do this:
<%
strImage = rsArticles.Fields.Item("IMAGE1").Value
response.write "<hr>Image = "& strImage &"<hr>"
If strImage <> "" then
%>
<img src="<%=strImage%>" width="32" height="32" /> <%=(rsArticles.Fields.Item("AD_TEXT").Value)%>
<%End If%>
Then tell us what the response writes. That will tell you exactly what the db is outputting for that field.