简体   繁体   中英

classic asp if statement issue

I have a if statement which I am pretty sure it is correct and should work. But for some reason it is not.

while not oRs2.EOF
if iCat = oRs2("id")  then
%>
   <div class ="<%= oRs2("id") %><%= iCat  %>">
<%
else
%>
   <div class ="faqquestion <%= oRs2("id") %><%= iCat  %>">
<%
end if
%>

And this is what you get.

<div class="faqquestion 11">
<div class="faqquestion 21">
<div class="faqquestion 31">

but what it should be

<div class="11">
<div class="faqquestion 21">
<div class="faqquestion 31">

cant see what i am doing wrong, 1 does = 1!?

how the variables are being set:

dim iCat
iCat = request.QueryString("cat")

dim sSQL
sSQL = "Select * from table"        
set oRs2 = oConn.Execute(sSQL)  

I think the problem is one of data typing.

For example I tested the following script (just take the contents and put into a file called test.vbs, then double click on it:

dim i
i = "1"

dim j
j=1

if i = j then
    msgbox "yes"
else
    msgbox "no"
end if
msgbox i & j

This will output "no" and "11".

In your code the iCat will be a string as you're just pulling it from request.QueryString so try converting it to an integer using CInt

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM