Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 8 of 8
  1. #1
    New Coder
    Join Date
    Apr 2005
    Posts
    53
    Thanks
    2
    Thanked 0 Times in 0 Posts

    image paths query for multiple image paths

    Hello,

    I need to build a sql query to a table that has multiple columns for 6 different image paths that would check for the existence of a path in each column, then call the image paths for display of each existing image in a table cell.

    What I currently have can only display one existing image or displays a broken image icon when more than one image exists. I'm just stumped on how to get it to display all existing images. Here's the code...

    <td>
    <img src="<%= rs("image_path")%><%= rs("image_path2")%>
    <%= rs("image_path3")%><%= rs("image_path4")%>
    <%= rs("image_path5")%><%= rs("image_path6")%>">
    </td>

    Any assistance would be greatly appreciated.

    Anessa

  • #2
    Senior Coder nikkiH's Avatar
    Join Date
    Jun 2005
    Location
    Near Chicago, IL, USA
    Posts
    1,973
    Thanks
    1
    Thanked 32 Times in 31 Posts
    tmpImg = rs("image_path")
    If tmpImg <> "" Then
    Response.Write "<img src='"+ tmpImg + "'>
    End If
    tmpImg = rs("image_path2")
    If tmpImg <> "" Then
    Response.Write "<img src='"+ tmpImg + "'>
    End If

    etc
    Or you could put it in a From 1 To 6 Loop if you feel creative or hate typing.

    If this post contains any code, I may or may not have tested it. It's probably just example code, so no getting knickers in a bunch over a typo, OK? If it doesn't have basic error checking in it, such as object detection or checking if objects are null before using them, put that in there. I'm giving examples, not typing up your whole app for you. You run code at your own risk.
    Bored? Visit
    http://www.kaelisspace.com/

  • #3
    New Coder
    Join Date
    Apr 2005
    Posts
    53
    Thanks
    2
    Thanked 0 Times in 0 Posts
    Thank you. Sorry to sound like a moron, but I am new to building these queries and need to know where to place your code. Below is the page I'm working with...

    <%
    Sub buildSqlStatement()
    if isNull(request.queryString("searchType")) = false then '## verify paramater was sent
    if trim(request.queryString("searchType")) <> "" then ' ## verify paramater is valid
    searchType = request.queryString("searchType") ' ## localize Paramater

    '###### Identify search type ####################
    select case searchType
    case "org"
    '##### Org search type #####################
    getRecordSet "select * from events where orgId =" & request.form("orgList") & " order by postDate"
    '##### End Org search type #####################

    case "multi"
    '##### Multi search type #######################
    stateP = request.form("stateList") '## localize state paramater value
    dateP = request.form("dateList") '## localize date paramater value
    typeP = request.form("typeList") '## localize type paramater value

    firstParam = false '## boolean for determining format of sql statement
    multiSql = "" '## variable used for storing where clause of sql statement
    if stateP <> "All" then '### validate if specific state was chosen
    firstParam = true
    multiSql = " where state = '" & stateP & "' "
    end if
    if dateP <> "All" then '### validate if specific date was chosen
    if firstParam = true then
    multiSql = multiSql & " and DATEDIFF(day , postDate , getdate()) <" & dateP & " "
    else
    firstParam = true
    multiSql = " where DATEDIFF(day , postDate , getdate()) <" & dateP & " "
    end if
    end if
    if typeP <> "All" then '### validate if specific type was chosen
    if firstParam = true then
    multiSql = multiSql & " and type =" & typeP & " "
    else
    multiSql = " where type =" & typeP & " "
    end if
    firstParam = true
    end if
    if firstParam = true then
    getRecordSet "select * from events " & multiSql & " order by day_start"
    else
    getRecordSet "select * from events " & multiSql & " order by day_start"
    end if

    '##### End Multi search type ########################

    case "keyWord"
    '##### KeyWord search type #####################
    getRecordSet "select * from events where ( description like '%" & request.form("keyWord") & "%' or title like '%" & request.form("keyWord") & "%' ) order by day_start"
    '##### KeyWord search type #####################
    end select
    else
    'call catchError '## if login is invalid run error routine
    end if
    else
    'call catchError '## if login has expired run error routine
    end if

    End Sub

    Sub displaySelectedEvents()
    if rs.eof then '## if no events match selected criteria
    Response.Write "<p>No events posted that match your criteria<p>"
    else
    do while not rs.eof '##### iterate entire data set
    %>
    <tr align="left" valign="top">
    <td>
    <img src="<%= rs("image_path")%><%= rs("image_path2")%><%= rs("image_path3")%><%= rs("image_path4")%><%= rs("image_path5")%><%= rs("image_path6")%>">
    </td>
    <td>
    <%= rs("ceMonth")%> / <%= rs("day_start")%> - <%= rs("day_end")%>, <%= rs("ceYear")%>
    </td>
    <td>
    <b><a href="<%=rs("url")%>" target="_blank"><%=rs("title")%></a></b>
    <br>
    <%= rs("description")%>
    </td>
    <td>
    <%= rs("city")%>, <%= rs("state")%>
    </td>
    <td>
    <%= rs("typeName")%>
    </td>
    </tr>
    <%
    rs.moveNext
    loop
    end if
    End Sub
    %>

    Thanks again,
    Anessa

  • #4
    Senior Coder nikkiH's Avatar
    Join Date
    Jun 2005
    Location
    Near Chicago, IL, USA
    Posts
    1,973
    Thanks
    1
    Thanked 32 Times in 31 Posts
    The CODE button is your friend for long code posts.

    Code:
    Sub displaySelectedEvents()
       if rs.eof then '## if no events match selected criteria
          Response.Write "<p>No events posted that match your criteria<p>"
       else
          do while not rs.eof '##### iterate entire data set
       %>
       <tr align="left" valign="top">
          <td>
          <%
          tmpImg = rs("image_path")
          If tmpImg <> "" Then
             Response.Write "<img src='"+ tmpImg + "'>
          End If
          For X = 2 To 6     
             tmpImg = rs("image_path"&X)
             If tmpImg <> "" Then
                Response.Write "<img src='"+ tmpImg + "'>
             End If
          Next
          %>
          </td>
    Too bad you didn't call it image_path1...
    HTH

    If this post contains any code, I may or may not have tested it. It's probably just example code, so no getting knickers in a bunch over a typo, OK? If it doesn't have basic error checking in it, such as object detection or checking if objects are null before using them, put that in there. I'm giving examples, not typing up your whole app for you. You run code at your own risk.
    Bored? Visit
    http://www.kaelisspace.com/

  • #5
    New Coder
    Join Date
    Apr 2005
    Posts
    53
    Thanks
    2
    Thanked 0 Times in 0 Posts
    Thanks. I got it to work after inserting the closing quotes after the Response.Writes. You said, "Too bad you didn't call it image_path1...". If I change the database table column from 'image_path' to 'image_path1', how would it make the query easier? If I were to guess, would it be this...?

    Code:
    %>
       <tr align="left" valign="top">
          <td>
          <%
          tmpImg = rs("image_path")
          For X = 1 To 6     
             tmpImg = rs("image_path"&X)
             If tmpImg <> "" Then
                Response.Write "<img src='"+ tmpImg + "'>"
             End If
          Next
          %>
    Thanks again,
    Anessa
    Last edited by anessa05; 09-09-2005 at 04:50 AM. Reason: Left out quotes

  • #6
    Senior Coder nikkiH's Avatar
    Join Date
    Jun 2005
    Location
    Near Chicago, IL, USA
    Posts
    1,973
    Thanks
    1
    Thanked 32 Times in 31 Posts
    Oops. Sorry about the quotes.
    And yes, if you'd called it with the 1, it would be just like you have. No biggie, just a little less typing and cleaner logic.

    If this post contains any code, I may or may not have tested it. It's probably just example code, so no getting knickers in a bunch over a typo, OK? If it doesn't have basic error checking in it, such as object detection or checking if objects are null before using them, put that in there. I'm giving examples, not typing up your whole app for you. You run code at your own risk.
    Bored? Visit
    http://www.kaelisspace.com/

  • #7
    New Coder
    Join Date
    Apr 2005
    Posts
    53
    Thanks
    2
    Thanked 0 Times in 0 Posts
    Thank you so much for your help! It works great! I do have one more tweek I need to make to it. For when there are more than one image to display, how can I insert a <br>, so the images will be stacked vertically?

    Anessa

  • #8
    Senior Coder nikkiH's Avatar
    Join Date
    Jun 2005
    Location
    Near Chicago, IL, USA
    Posts
    1,973
    Thanks
    1
    Thanked 32 Times in 31 Posts
    Don't.
    Use display block instead if you want it displayed as a block instead of inline.
    <img style="display:block">

    Unless that farks up something else due to your layout. But it shouldn't.

    If this post contains any code, I may or may not have tested it. It's probably just example code, so no getting knickers in a bunch over a typo, OK? If it doesn't have basic error checking in it, such as object detection or checking if objects are null before using them, put that in there. I'm giving examples, not typing up your whole app for you. You run code at your own risk.
    Bored? Visit
    http://www.kaelisspace.com/


  •  

    Posting Permissions

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