Luk
Luk

Reputation: 55

little help on asp - response write

I set a variable :

Dim adoRecordset

and set it as:

Set adoRecordSet = Server.CreateObject("ADODB.RecordSet")

adoRecordset.Open mSQL , adoConnection , adOpenForwardOnly

and I use it into show my data from database

eg. 1. <td align="left"><%=adoRecordset("loc")%></td>

and I would like add a asp code "if" & "else"

but this : 2. Response.Write "<td adoRecordset(loc)></td>"

doesn't work.

How can I make asp code 2. work as 1. ?

Upvotes: 1

Views: 345

Answers (2)

Gary Richter
Gary Richter

Reputation: 537

Dim adoRecordset
Set adoRecordSet = Server.CreateObject("ADODB.RecordSet")

adoRecordset.Open mSQL , adoConnection , adOpenForwardOnly

if not adoRecordset.EOF then

    do while not adoRecordSet.EOF
        if adoRecordset("columnName") = "test value 1" then
            response.write("<td>" & adoRecordset("columnName") & "</td>")
        else
            response.write("<td>I want to do something else here</td>")
        end if

        adoRecordset.movenext
    loop
end if

adoRecordset.close
set adoRecordset = nothing

Upvotes: 0

StuartLC
StuartLC

Reputation: 107247

My asp classic is rusty, but I think you are looking for something like:

<% 
If adoRecordset("loc") <> "" Then
   Response.Write(adoRecordset("loc"))
End If
%>

Or with a local var to cache the result:

<% 
Dim someLoc
Set someLoc = adoRecordset("loc")
If someLoc <> "" Then
   Response.Write("<td>" & someLoc & "</td>")
End If
%>

If you've got large amounts of conditional Html output, then you can switch out of server code again, like so:

<% If something or other Then %>
  Some Conditional Html Here
<% Else %>
  Else Html here
<% End If %>

<%= is shorthand to emit a value whereas <% escapes to server side code.

Upvotes: 3

Related Questions