如果记录包含? [英] if record contains?

查看:52
本文介绍了如果记录包含?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在访问dbase中有一些记录,里面有一些东西


然后在网页上我有这个代码。


<%if cstr(rsProducts(" Logos"))=" OP"然后%>

< img name =" Logo" SRC ="图像/ op_big.gif" alt =" Out of print"

<%End if%>

<%if cstr(rsProducts(" Logos"))=" ; NLT"然后%>

< img name =" NLT" SRC ="图像/ NLTlogo.gif" alt =" New Living Translation"

<%End if%>

<%if cstr(rsProducts(" Logos"))=" ; LBK"然后%>

< img name =" Lbk" SRC ="图像/ LBklogo.gif" alt =" Living Books"

<%End if%>

<%if cstr(rsProducts(" Logos"))=" GM"然后%>

< img name =" Logo" SRC ="图像/ GMlogo.gif" alt =" Gold Medallion Award>

<%End if%>


但是,如果该字段有多个答案,则无效不工作。

(页面仍然可以使用,但它不会显示任何徽标)


如果有一个以上的徽标,它将在字段由一个

逗号


所以有时候每个标志都有一个标志组合,而且我想要

显示每个产品的相应徽标

NLT,LbK,GM等


是否有一个我可以使用的操作员,所以如果记录包含这样的那样的

而不是=

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 =

推荐答案

试试这个以提高效率!


<%

请勿使用rsProduct.EOF

strItem = Ucase(修剪(rsProducts(" Logos))))

如果Len(strItem)> 0然后

aryData = Split(strItem,",")

对于intCount = 0到UBound(aryData)

ReSponse.Write GetImage(aryData(intCount))

下一页

结束如果

rsProduct.MoveNext

循环


函数GetImage(strLogo)

选择案例UCase(修剪(strLogo))

案例OP

strImage =" images / op_big.gif"

strName =" Logo"

strAlt ="绝版>

案例NLT

strImage =" images / NLTlogo.gif"

strName =" NLT"

strAlt =" New Living翻译

案例LBK"

strImage =" images / LBklogo.gif"

strName =" Lbk"

strAlt =" Living Books"

Case" GM"

strImage =" images / GMlogo.gif"

strName =" Logo"

strAlt =" Gold Medallion A病房

Case Else

strImage =""

strName =""

strAlt = "

结束选择

如果Len(strImage)> 0然后

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,"")

结束如果

结束功能

%>


-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


或使用精选案例...


aryData = Split(strItem," ;,")

for intCount = 0到Ubound(aryData)

select case ucase(trim(aryData(intCount)))

caseOP:i =" op_big.gif":n =" Logo":a =" Out of print"
case" NLT":i =" NLTlog。 gif":n =" NLT":a =" New Living

翻译"

案例.........

case ........

结束选择

if i<> ""然后

response.write"< img src =''" &安培;我和我"''name =''" &安培; n& "''alt =''" &安培; a&

"''>"

结束如果

next


在2003年9月19日星期五18:59:08 -0500,dlbjr <做****** @ do.u>写道:
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

On Fri, 19 Sep 2003 18:59:08 -0500, "dlbjr" <do******@do.u> wrote:
试试这个效率!

<%
请不要rsProduct.EOF
strItem = Ucase(Trim( rsProducts(Logos)))
如果Len(strItem)> 0然后
aryData = Split(strItem,",")
对于intCount = 0到UBound(aryData)
ReSponse.Write GetImage(aryData(intCount))
下一步
结束如果
rsProduct.MoveNext
循环

函数GetImage(strLogo)
选择案例UCase(修剪(strLogo))
案例& ; OP"
strImage =" images / op_big.gif"
strName =" Logo"
strAlt =" Out of print"
案例NLT
strImage =" images / NLTlogo.gif"
strName =" NLT"
strAlt =" New Living Translation"
Case" LBK"
strImage =" ;图像/ LBklogo.gif"
则strName = QUOT; LBK"
strAlt = QUOT;生活图书"
外壳" GM"
strImage = QUOT;图像/ GMlogo.gif" ;
strName =" Logo"
strAlt =" Gold Medallion Award"
Case Else
strImage =""
strName ="" < br / > strAlt =""
结束选择
如果Len(strImage)> 0然后
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 =加入(ary,"")
结束如果
结束功能
%>

-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






哇,你们完全失去了我。我根本不知道vb,只是根据我在Dreamweaver生成的页面上看到的
代码。你的东西

看起来比我复杂,我不确定我完全理解

它。


我粘贴了来自我的rs查询的dlbjr的代码我得到了这个错误


错误类型:

Microsoft VBScript运行时(0x800A01A8)

需要的对象:''rsProduct''

/copy/pdetails.asp,第26行
其次,我如何使用你所做的功能?

就像这样

<%= GetImage%> ?


我明显检查了但是我粘贴了这个错误。


这是我的代码,你可以看到,第26行是你的循环的开始

<! - #include file =" Connections / connMain.asp" - >

将%

尺寸rsProducts__MMColParam

rsProducts__MMColParam = QUOT 1 QUOT;

。如果(请求.QueryString(QUOT; ISBN")<>"")然后

rsProducts__MMColParam =的Request.QueryString(QUOT; ISBN")

结束如果

%>

<%

Dim rsProducts

Dim rsProducts_numRows


设置rsProducts =的Server.CreateObject(QUOT; ADODB.Recordset")

rsProducts.ActiveConnection = MM_connMain_STRING

rsProducts.Source = QUOT; SELECT * FROM产品WHERE ISBN =' " +

替换(rsProducts__MMColParam,"''","''''")+"''"

rsProducts.CursorType = 0

rsProducts.CursorLocation = 2

rsProducts.LockType = 1

rsProducts.Open()


rsProducts_numRows = 0

%>


<%

请勿rsProduct.EOF< - 第26行

strItem = Ucase(修剪(rsProducts(" Logos")))

如果Len(strItem)> 0然后

aryData = Split(strItem,",")

对于intCount = 0到UBound(aryData)

ReSponse.Write GetImage(aryData(intCount))

下一页

结束如果

rsProduct.MoveNext

循环


函数GetImage(strLogo)

选择案例UCase(修剪(strLogo))

案例OP

strImage =" images / op_big.gif"

strName =" Logo"

strAlt ="绝版>

案例NLT

strImage =" images / NLTlogo.gif"

strName =" NLT"

strAlt =" New Living翻译

案例LBK"

strImage =" images / LBklogo.gif"

strName =" Lbk"

strAlt =" Living Books"

Case" GM"

strImage =" images / GMlogo.gif"

strName =" Logo"

strAlt =" Gold Medallion A病房

Case Else

strImage =""

strName =""

strAlt = "

结束选择

如果Len(strImage)> 0然后

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,"")

结束如果

结束功能

%>

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


这篇关于如果记录包含?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆