if record contains?

R

Robert Blackwell

I have a record in an access dbase that has some stuff in it

and then on a web page I have this code.

<% If cstr(rsProducts("Logos")) = "OP" Then %>
<img name="Logo" src="images/op_big.gif" alt="Out of Print">
<% End If %>
<% If cstr(rsProducts("Logos")) = "NLT" Then %>
<img name="NLT" src="images/NLTlogo.gif" alt="New Living Translation">
<% End If %>
<% If cstr(rsProducts("Logos")) = "LBk" Then %>
<img name="Lbk" src="images/LBklogo.gif" alt="Living Books">
<% End If %>
<% If cstr(rsProducts("Logos")) = "GM" Then %>
<img name="Logo" src="images/GMlogo.gif" alt="Gold Medallion Award>
<% End If %>

This works, however, if the field has more then one answer it wont work.
(the page still works, but it wont display any logos)

If there is more then one logo, it would be separated in the field by a
comma

so sometimes there are a combination of logos for each one, and I want to
display the appropriate logos for each product
NLT, LbK, GM etc.

is there an operator I can use so if it the record contains such and such
instead of =
 
D

dlbjr

Try this for efficiency!

<%
Do While Not rsProduct.EOF
strItem = Ucase(Trim(rsProducts("Logos")))
If Len(strItem) > 0 Then
aryData = Split(strItem,",")
For intCount = 0 To UBound(aryData)
ReSponse.Write GetImage(aryData(intCount))
Next
End If
rsProduct.MoveNext
Loop

Function GetImage(strLogo)
Select Case UCase(Trim(strLogo))
Case "OP"
strImage = "images/op_big.gif"
strName = "Logo"
strAlt = "Out of Print"
Case "NLT"
strImage = "images/NLTlogo.gif"
strName = "NLT"
strAlt = "New Living Translation"
Case "LBK"
strImage = "images/LBklogo.gif"
strName = "Lbk"
strAlt = "Living Books"
Case "GM"
strImage = "images/GMlogo.gif"
strName = "Logo"
strAlt = "Gold Medallion Award"
Case Else
strImage = ""
strName = ""
strAlt = ""
End Select
If Len(strImage) > 0 Then
Dim ary(6)
ary(0) = "<img name='"
ary(1) = strName
ary(2) = " src='"
ary(3) = strImage
ary(4) = "' alt='"
ary(5) = strAlt
ary(6) = "'>"
GetImage = Join(ary,"")
End If
End Function
%>

-dlbjr

Discerning resolutions for the alms
 
D

Dan Brussee

or using select case...

aryData = Split(strItem,",")
for intCount = 0 to Ubound(aryData)
select case ucase(trim(aryData(intCount)))
case "OP": i = "op_big.gif": n = "Logo": a = "Out of print"
case "NLT": i = "NLTlog.gif": n = "NLT": a = "New Living
Translation"
case.........
case........
end select
if i <> "" then
response.write "<img src='" & i & "' name='" & n & "' alt='" & a &
"'>"
end if
next
 
R

Robert Blackwell

wow, you guys totally lost me. I don't know vb at all, just putting together
code based one what I see on the page that dreamweaver generated. Your stuff
looks more complicated then mine and I'm not sure I completely understand
it.

I pasted the code from dlbjr right under my rs query and I get this error

Error Type:
Microsoft VBScript runtime (0x800A01A8)
Object required: 'rsProduct'
/copy/pdetails.asp, line 26


Secondly, how do I use the function you made?
Just like this
<%= GetImage %> ?

I'd check obviously but I got that error I pasted.

Here's my code, as you can see, line 26 is the beginning of your loop


<!--#include file="Connections/connMain.asp" -->
<%
Dim rsProducts__MMColParam
rsProducts__MMColParam = "1"
If (Request.QueryString("ISBN") <> "") Then
rsProducts__MMColParam = Request.QueryString("ISBN")
End If
%>
<%
Dim rsProducts
Dim rsProducts_numRows

Set rsProducts = Server.CreateObject("ADODB.Recordset")
rsProducts.ActiveConnection = MM_connMain_STRING
rsProducts.Source = "SELECT * FROM Products WHERE ISBN = '" +
Replace(rsProducts__MMColParam, "'", "''") + "'"
rsProducts.CursorType = 0
rsProducts.CursorLocation = 2
rsProducts.LockType = 1
rsProducts.Open()

rsProducts_numRows = 0
%>

<%
Do While Not rsProduct.EOF <-- Line 26
strItem = Ucase(Trim(rsProducts("Logos")))
If Len(strItem) > 0 Then
aryData = Split(strItem,",")
For intCount = 0 To UBound(aryData)
ReSponse.Write GetImage(aryData(intCount))
Next
End If
rsProduct.MoveNext
Loop

Function GetImage(strLogo)
Select Case UCase(Trim(strLogo))
Case "OP"
strImage = "images/op_big.gif"
strName = "Logo"
strAlt = "Out of Print"
Case "NLT"
strImage = "images/NLTlogo.gif"
strName = "NLT"
strAlt = "New Living Translation"
Case "LBK"
strImage = "images/LBklogo.gif"
strName = "Lbk"
strAlt = "Living Books"
Case "GM"
strImage = "images/GMlogo.gif"
strName = "Logo"
strAlt = "Gold Medallion Award"
Case Else
strImage = ""
strName = ""
strAlt = ""
End Select
If Len(strImage) > 0 Then
Dim ary(6)
ary(0) = "<img name='"
ary(1) = strName
ary(2) = " src='"
ary(3) = strImage
ary(4) = "' alt='"
ary(5) = strAlt
ary(6) = "'>"
GetImage = Join(ary,"")
End If
End Function
%>
 
D

dlbjr

<!--#include file="Connections/connMain.asp" -->
<%
strMMColParam = "1"
strISBN = Trim(Request.QueryString("ISBN"))
If strISBN <> "" Then
strMMColParam = strISBN
End If
strMMColParam = Replace(strMMColParam, "'", "''")
rs.ActiveConnection = MM_connMain_STRING
strSQL = "SELECT LOGOS, ISBN FROM PRODUCTS WHERE ISBN = '" & strMMColParam &
"'"
Set rs = Server.CreateObject("ADODB.Recordset")
rs.CursorLocation = 2
rs.Open strSQL,MM_connMain_STRING,MM_connMain_STRING,0,1
Do While Not rs.EOF
strItem = Ucase(Trim(rs("Logos")))
If Len(strItem) > 0 Then
aryData = Split(strItem,",")
For intCount = 0 To UBound(aryData)
ReSponse.Write GetImage(aryData(intCount))
Next
End If
rs.MoveNext
Loop
rs.Close
Set rs = Nothing

Function GetImage(strLogo)
Select Case UCase(Trim(strLogo))
Case "OP"
strImage = "images/op_big.gif"
strName = "Logo"
strAlt = "Out of Print"
Case "NLT"
strImage = "images/NLTlogo.gif"
strName = "NLT"
strAlt = "New Living Translation"
Case "LBK"
strImage = "images/LBklogo.gif"
strName = "Lbk"
strAlt = "Living Books"
Case "GM"
strImage = "images/GMlogo.gif"
strName = "Logo"
strAlt = "Gold Medallion Award"
Case Else
strImage = ""
strName = ""
strAlt = ""
End Select
If Len(strImage) > 0 Then
Dim ary(6)
ary(0) = "<img name='"
ary(1) = strName
ary(2) = " src='"
ary(3) = strImage
ary(4) = "' alt='"
ary(5) = strAlt
ary(6) = "'>"
GetImage = Join(ary,"")
End If
End Function
%>
 
D

dlbjr

<!--#include file="Connections/connMain.asp" -->
<%
strMMColParam = "1"
strISBN = Trim(Request.QueryString("ISBN"))
If strISBN <> "" Then
strMMColParam = strISBN
End If
strMMColParam = Replace(strMMColParam, "'", "''")
strSQL = "SELECT LOGOS, ISBN FROM PRODUCTS WHERE ISBN = '" & strMMColParam &
"'"
Set rs = Server.CreateObject("ADODB.Recordset")
rs.CursorLocation = 2
rs.Open strSQL,MM_connMain_STRING,MM_connMain_STRING,0,1
Do While Not rs.EOF
strItem = Ucase(Trim(rs("Logos")))
If Len(strItem) > 0 Then
aryData = Split(strItem,",")
For intCount = 0 To UBound(aryData)
ReSponse.Write GetImage(aryData(intCount))
Next
End If
rs.MoveNext
Loop
rs.Close
Set rs = Nothing

Function GetImage(strLogo)
Select Case UCase(Trim(strLogo))
Case "OP"
strImage = "images/op_big.gif"
strName = "Logo"
strAlt = "Out of Print"
Case "NLT"
strImage = "images/NLTlogo.gif"
strName = "NLT"
strAlt = "New Living Translation"
Case "LBK"
strImage = "images/LBklogo.gif"
strName = "Lbk"
strAlt = "Living Books"
Case "GM"
strImage = "images/GMlogo.gif"
strName = "Logo"
strAlt = "Gold Medallion Award"
Case Else
strImage = ""
strName = ""
strAlt = ""
End Select
If Len(strImage) > 0 Then
Dim ary(6)
ary(0) = "<img name='"
ary(1) = strName
ary(2) = " src='"
ary(3) = strImage
ary(4) = "' alt='"
ary(5) = strAlt
ary(6) = "'>"
GetImage = Join(ary,"")
End If
End Function
%>

-dlbjr

Discerning resolutions for the alms
 
A

Aaron Bertrand [MVP]

<img name="Logo" src="images/op_big.gif" alt="Out of Print">

Why not store the path information for the logo along with the data in the
database, rather than having to modify the ASP page every time the path
changes, or a product's logo(s) change?
If there is more then one logo, it would be separated in the field by a
comma

Well, if this is a many-to-one relationship, you need to alter your design.
Let's say your current table looks like this:

CREATE TABLE Products
(
ProductID INT,
...other stuff...,
Logos VARCHAR(3)
)

Instead, you could do this:

CREATE TABLE Products
(
ProductID INT,
...other stuff...
)

CREATE TABLE ProductLogos
(
ProductID INT,
LogoID INT
)

CREATE TABLE Logos
(
LogoID INT,
imagePath VARCHAR(255)
)

Then your query would be:

SELECT
p.ProductID, l.imagePath
FROM Products p
LEFT OUTER JOIN ProductLogos pl
ON p.ProductID = pl.productID
LEFT OUTER JOIN Logos l
ON pl.logoID = l.logoID

And your ASP code would be:

<%
set rs = conn.execute(query)
cProductID = 0
do while not rs.eof
if rs(0) <> cProductID
' new product
cProductID = rs(0)
response.write cProductID & "<p>"
else
' same product, second logo
response.write "<img src='images/" & rs(1) & "'>"
end if
rs.movenext
loop
%>

Isn't that easier than hard-coding a bunch of if/else or select case logic
into your ASP?
 
A

Aaron Bertrand [MVP]

Let me revise the ASP code a bit.

<%
set rs = conn.execute(query)
cProductID = 0
do while not rs.eof
if rs(0) <> cProductID
' new product
cProductID = rs(0)
response.write cProductID & "<p>"
if not isnull(rs(1)) then
response.write "<img src='images/" & rs(1) & "'>"
end if
else
' same product, second logo
response.write "<img src='images/" & rs(1) & "'>"
end if
rs.movenext
loop
%>
 
R

Robert Blackwell

dlbjr

On your most recent suggestion, it errored on the sql query so I changed it
to this...
strSQL = "SELECT * FROM Products WHERE ISBN = '" + Replace(strMMColParam,
"'", "''") + "'"
and then after that it errors on Line35

rs.Open strSQL,MM_connMain_STRING,MM_connMain_STRING,0,1

Aaron, I didn't make the dbase, it's something I'm supplied with so I need
to leave it as is, or else updates will be a PIA

The cell that contains the information about logos doesn't relate to
anything else, and it would be a bigger hassle to try and do that
(especially since I have to rely on the publisher for a new dbase with
updates every month)
 
R

Robert Blackwell

rs.Open strSQL,MM_connMain_STRING,MM_connMain_STRING,0,1


I tried removing the second MM_connMain_STRING and then after that, it
errored on Line 131 which is where I try to call the GetImage function

<%= GetImage %>

so, I guess I just didn't do it right.
 
R

Robert Blackwell

Okay, well I finallly got the function call line right

<%= GetImage(strLogo) %>

But when I load the page, it doesn't work unfortunately.

Instead of it displaying any images, it doesn't.

But there is a broken image on the top left of the page for the nlt logo set
to a strange width (140x30) if you right click/properties on the image,
there is no info about the image except the dimensions and if yo uview the
source of the page

<img name='NLT src='images/NLTlogo.gif' alt='New Living Translation'>
this code is placed at the very top, before the html tags.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,102
Messages
2,570,645
Members
47,243
Latest member
CorrineCad

Latest Threads

Top