Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature may not be available in some browsers.
Dim foundFlag
foundFlag = false
Do Until rs.EOF
If rs("ip") = strIP Then foundFlag = true
rs.MoveNext
Loop[code]
Then you could do your if check against the foundFlag. If foundFlag is true than the loop fopund one in the process of moving throught the recordset, otherwise it didn't. To speed this up you could make it exit the loop upon finding a match:
[code]Dim foundFlag
foundFlag = false
Do Until rs.EOF
If rs("ip") = strIP Then
foundFlag = true
Exit Loop 'check syntax here, I am a little sleepy
End If
rs.MoveNext
Loop[code]
Now it only loops all the way through the recordset if it doesn't find a match, otherwise it sets the flag and jumps out after a single match is found.
Unfortunatly this is a little slow when it somes to processing, or rather, there is a much quicker way of doing it. If you allow the database to do the work for you, then you can take advantage of the fact that it has been optimized in search techniques. Another advantage is that less data will be transmitted between your script and the database. In fact, if we do this correctly, then only a single record will need to be returned at most, instead of the entire contents of the table.
Ok, so we wil want to change your sql statement like so:
[code]
rsip = "SELECT * FROM ip WHERE ip = '" & strIP & "'"
If rs.EOF Then 'a recordset is only returned EOF if it is empty
'execute your insert here
'query for the newly added user
'execute your update here
Else 'rs is not empty, so this ip is already in db
Response.Write "Sorry you have already answered this question"
End If
Original New Name
rsip sql_checkIP
sql sql_addVote
sqlIP sql_addIP
rs rs_checkIP
set rs = conn.execute (rsip)
rsip = "select ip from ip WHERE ip = '" & strIP & "'"