Link to home
Start Free TrialLog in
Avatar of sl1nger
sl1nger

asked on

Display query results into HTML using ASP

I have an ASP page and would like the query result to display in html
my example:

dim sSQL, adoRS

sSQL = "Select UserID, UserName, UserEmail from tbl Users"

Do Until adoRS.EOF
  iSource = 0
      Do Until iSource = (adoRS.Fields.Count)
         response.write "<td>" &UserID & "</td>"
         response.write "<td>" & UserName & "</td>"
         response.write "<td>" & UserEmail & "</td>"
         iSource = iSource + 1
   Loop
   adoRS.MoveNext
Loop
adoRS.close

How should I do this??  Any help appreciated.. Thanks in Advance.
ASKER CERTIFIED SOLUTION
Avatar of m8rix
m8rix
Flag of Australia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of gladxml
gladxml

you can also try this...

===
<%
dim sSQL, adoRS
set adoRS=Server.CreateObject("ADODB.recordset")
sSQL = "Select UserID, UserName, UserEmail from tbl Users"
'assuming that your connection object is conn then
rs.Open sql, conn
%>
<table>
<%
if not(adoRS.EOF) then
Do while not(adoRS.EOF)%>
  <tr>  
   <td><%=adoRS("UserID")%></td>
   <td><%=adoRS("UserName")%></td>
  <td><%=adoRS("UserEmail")%></td>
   </tr>
   <%adoRS.MoveNext
Loop
end if
adoRS.close%>
</table>

===

You can also look at the link below might help...

http://www.w3schools.com/ado/ado_query.asp

HTH...

Happy programming...

Hi,

         This is another way of displaying with the Table Headings.

Response.write "<table border=1 cellspacing=1 cellpadding=1>"
Response.write "<TR>"
Response.write "<td valign=top>No</TD>"
Response.write "<td valign=top>UserID</TD>"
Response.write "<td valign=top>User Name</TD>"
Response.write "<td valign=top>Email</TD>"
Response.write "</tr>"

dim sSQL, adoRS
iSource = 0
sSQL = "Select UserID, UserName, UserEmail from tbl Users"
set adoRS = Dbobj.execute(ssql)

if not adoRS.EOF then
  Do Until adoRS.EOF
       iSource = iSource + 1
         Response.write "<TR>"
         response.write "<td>" &iSource& "</td>"
         response.write "<td>" &adoRS("UserID")& "</td>"
         response.write "<td>" & adoRS("UserName")&  "</td>"
         response.write "<td>" & adoRS("UserEmail")&  "</td>"
         Response.write "</tr>"
         adoRS.MoveNext
   Loop
end if

Response.write "</table>"
adoRS.close

Hope this would be Helpful to you.

Avatar of sl1nger

ASKER

How can I add a row count?  If possible, I'd like to display the number of results; w/out writing another query.
Avatar of sl1nger

ASKER

I'd also like to alternate colors between each row. White, grey, white, grey, etc.
Hi sl1nger, thanks for the points!

The following code will answer your additional questions.

Reg's
m8rix

<%
dim sSQL, adoRS

sSQL = "Select UserID, UserName, UserEmail from tbl Users"
BackColor = "#FFFFFF"
Counter = 0

response.write "<table>"
Do Until adoRS.EOF
   Counter = Counter + 1
   if BackColor = "#FFFFFF" then
      BackColor = "#FBFBFB"
   Else
      BackColor = "#FFFFFF"
   End if
   response.write "<tr style=""background-color: " & BackColor & """>"  
   response.write "<td>" & Counter & "</td>"
   response.write "<td>" & adoRS("UserID") & "</td>"
   response.write "<td>" & adoRS("UserName") & "</td>"
   response.write "<td>" & adoRS("UserEmail") & "</td>"
   response.write "</tr>"
   adoRS.MoveNext
Loop
response.write "</table>"
adoRS.close
%>