Beginner
Beginner

Reputation: 29573

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)  

Upvotes: 1

Views: 528

Answers (1)

Jon Egerton
Jon Egerton

Reputation: 41589

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

Upvotes: 1

Related Questions