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

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.
0
sl1nger
Asked:
sl1nger
1 Solution
 
m8rixCommented:
Hi sl1nger! Is this what you mean?

dim sSQL, adoRS

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

response.write "<table>"
Do Until adoRS.EOF
   response.write "<tr>"  
   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
0
 
gladxmlCommented:
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...

0
 
casstdCommented:
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.

0
Cloud Class® Course: Amazon Web Services - Basic

Are you thinking about creating an Amazon Web Services account for your business? Not sure where to start? In this course you’ll get an overview of the history of AWS and take a tour of their user interface.

 
sl1ngerAuthor Commented:
How can I add a row count?  If possible, I'd like to display the number of results; w/out writing another query.
0
 
sl1ngerAuthor Commented:
I'd also like to alternate colors between each row. White, grey, white, grey, etc.
0
 
m8rixCommented:
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
%>
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

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