PDA

View Full Version : Comparing query string to recordset field to disable a link


iridium192
06-19-2003, 11:04 AM
I am trying to display a list of records, each with a link that changes the value of a query string in turn changing the content of the page and disabling the link of the selected record. *deep breath*

If I declare the “value2” variable outside the loop it doesn’t change the value from one record to the next. All records would have the same value2 as the first record in the loop.

If I add <% value1 %> = <% value2 %> within the loop I get the right values for each record. Im not sure why the if then expression doesn’t work.

If I change “value2” to a static value that reflects a specific record (ie value2 = “5”) it does change the link for that record.

The data type of field1 is number. There are no extra spaces.

Thanks for any help.

<%
While ((Repeat__numRows <> 0) AND (NOT recordset.EOF))
%>

<% Dim value1, value2
value1 = Request.QueryString("string1")
value2 = recordset.Fields.Item("field1").Value
%>

<% If value2 = value1 Then %>nolink<% Else %><a href="?string1=<%=( recordset.Fields.Item("field1").Value)%>link</a><% End If %>

<%
Repeat__index=Repeat__index+1
Repeat__numRows=Repeat__numRows-1
recordset.MoveNext()
Wend
%>

Angelika
06-19-2003, 12:15 PM
Hi! Try this.

<%
Dim value1, value2
value1 = Request.QueryString("string1")
value1=Cint(value1)

Do While ((Repeat__numRows <> 0) AND (NOT recordset.EOF))
value2 = recordset.Fields.Item("field1").Value
'or
'value2 = recordset("field1").


If value2 = value1 Then
%>
nolink
<% Else %>
<a href="?string1=<%=recordset.Fields.Item("field1").Value%>">link</a>
'or
'<a href="?string1=<%=recordset("field1")%>">link</a>

<% End If %>

<%
Repeat__index=Repeat__index+1
Repeat__numRows=Repeat__numRows-1
recordset.MoveNext()
Loop
%>

Kodo
06-19-2003, 01:09 PM
I would suggest something along the same lines as Angelika.. the only thing different is I would completely ensure that the variables were Cint by doing this

If Cint(value2) = Cint(value1) Then


instead of doing this
value1 = Request.QueryString("string1")
value1=Cint(value1)


why does this happen? remember that ASP variables are of type VARIANT and are not specified as int or string or object or what ever.. so you have a querystring that is interpreted as a string and not a integer and of course a string and an integer cannot equal eachother :)
HTH

iridium192
06-19-2003, 01:12 PM
I added the line:

value1=CInt(value1)

and all is well.

Thanks again.