We help IT Professionals succeed at work.

Classic ASP Looping: if statement not working

wcotech
wcotech asked
on
Medium Priority
1,105 Views
Last Modified: 2012-08-14
I started develping in classic ASP a few years ago and have just been asked to revisit an application I created.  Well, I'm trying to dust off the shelves of my ASP knowledge but for some reason I can't get this "if statement" to return true while looping through the returned recordset.  Here's what's outputed to the browser from the attached code:

bad*****1||1
bad*****2||1
bad*****3||1
bad*****4||1
bad*****5||1
bad*****6||1
bad*****638||1
bad*****7||1
bad*****8||1
bad*****639||1

Why doesn't the first line return "good" (true)?  I know it's probably something very simple but I've spent an hour on this already and I don't have much more time to devote to it.
strsql = ""
	strsql = strsql & "SELECT TOP 10 siteid,site_name,address FROM sites ORDER BY site_name"
	'response.write strsql
	set rsSites = Server.CreateObject("ADODB.Recordset")
	set rsSites = dbConn.execute(strsql)
	
	if rsSites.EOF = True then
		response.write "No sites on file"
		response.end
	end if
 
	siteArray = rsSites.Getrows()
	'Name fields
	Const siteid = 0
	Const site_name = 1
	Const address = 2
		
	rsSites.close
	set rsSites = nothing	
	
	for irowloop = 0 to ubound(siteArray,2)
		selected = ""
		if (siteArray(siteid,irowloop)) = request.querystring("id") Then
			response.write "good"
		else 
			response.write "bad"
		end if
		response.write "*****"&(siteArray(siteid,irowloop))&"||"&request.querystring("id")&"<br>"
	next

Open in new window

Comment
Watch Question

Suspect it is to do with one value being numeric and the other text, try swapping the line

if (siteArray(siteid,irowloop)) = request.querystring("id") Then

with

if cdbl((siteArray(siteid,irowloop)))= cdbl(request.querystring("id")) Then

Commented:
change
if rsSites.EOF = True then
            response.write "No sites on file"
            response.end
      end if
 


to

if rsSites.EOF  then
            response.write "No sites on file"
            response.end
      end if
 

Author

Commented:
Beautiful!  I knew it was something simple.  Thanks for your help!

Explore More ContentExplore courses, solutions, and other research materials related to this topic.