...

View Full Version : image paths query for multiple image paths



anessa05
09-08-2005, 03:36 PM
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

nikkiH
09-08-2005, 07:04 PM
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. ;)

anessa05
09-08-2005, 08:17 PM
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

nikkiH
09-08-2005, 09:53 PM
The CODE button is your friend for long code posts. :D



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

anessa05
09-09-2005, 03:49 AM
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...?



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

nikkiH
09-09-2005, 02:02 PM
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.

anessa05
09-09-2005, 07:15 PM
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

nikkiH
09-09-2005, 08:31 PM
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.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum