• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1091
  • Last Modified:

Classic ASP Looping: if statement not working

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

0
wcotech
Asked:
wcotech
1 Solution
 
R_HarrisonCommented:
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
0
 
GawaiCommented:
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
 
0
 
wcotechAuthor Commented:
Beautiful!  I knew it was something simple.  Thanks for your help!
0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now