www.webdeveloper.com
Results 1 to 14 of 14

Thread: ASP Classifieds -- displaying the images

  1. #1
    Join Date
    Feb 2009
    Posts
    22

    Question ASP Classifieds -- displaying the images

    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!

  2. #2
    Join Date
    Jan 2008
    Location
    Florida
    Posts
    1,227
    If rs("IMAGE1") <> "" then

    <img src="<&#37;=rs("IMAGE1")%>">

  3. #3
    Join Date
    Feb 2009
    Posts
    22
    Quote Originally Posted by yamaharuss View Post
    If rs("IMAGE1") <> "" then

    <img src="<%=rs("IMAGE1")%>">

    Am I supposed to add something here? Sorry, I'm a code newbie.

  4. #4
    Join Date
    Jan 2008
    Location
    Florida
    Posts
    1,227
    Then you need to post your code.

  5. #5
    Join Date
    Feb 2009
    Posts
    22
    Here's what I have so far.

    In the head:

    Code:
    <%
    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:

    Code:
    <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.

  6. #6
    Join Date
    Jan 2008
    Location
    Florida
    Posts
    1,227
    <&#37;
    strImage = rsArticles.Fields.Item("IMAGE1").Value
    If strImage <> "" then
    %>
    <img src="<%=strImage%>" width="32" height="32" /> <%=(rsArticles.Fields.Item("AD_TEXT").Value)%>
    <%End If%>

  7. #7
    Join Date
    Feb 2009
    Posts
    22
    I'm still getting blank images appearing.
    http://ads.butlereagle.com/Classifie...h/articles.asp
    Is there something else that's supposed to go here?
    If strImage <> "" then

  8. #8
    Join Date
    Jan 2008
    Location
    Florida
    Posts
    1,227
    Are they blank or are the fields NULL?

    If you have NULL fields then simply change the code to:

    <&#37;
    strImage = rsArticles.Fields.Item("IMAGE1").Value & ""
    If strImage <> "" then
    %>
    <img src="<%=strImage%>" width="32" height="32" /> <%=(rsArticles.Fields.Item("AD_TEXT").Value)%>
    <%End If%>

  9. #9
    Join Date
    Jan 2008
    Location
    Florida
    Posts
    1,227
    Ya know, I looked at your link and didn't see any images at all.

  10. #10
    Join Date
    Feb 2009
    Posts
    22
    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!

  11. #11
    Join Date
    Feb 2009
    Posts
    22
    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.

    Code:
    <%
    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:

    Code:
    <img src="<%=(rsArticles.Fields.Item("IMAGE1").Value)%>" />
    See previous posts for my header code.

    Thanks!

  12. #12
    Join Date
    Jan 2008
    Location
    Florida
    Posts
    1,227
    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??

  13. #13
    Join Date
    Feb 2009
    Posts
    22
    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.

  14. #14
    Join Date
    Jan 2008
    Location
    Florida
    Posts
    1,227
    do this:
    Code:
    <&#37;
    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.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles