Discussion Locked

Build a HTML table dynamically

0 helpful
6 replies
Closed to new repliesThis discussion is closed. It stays readable, but it takes no new replies.

I'm fairly new to web development and I'm trying to figure out something that should be fairly straight forware:

I have a page and the user enters a beginning date and an ending date. I want to use ASP/VBScript to run a SQL query and get back a recordset from MSAccess. Then loop through the recordset displaying the results in a table on the page. I've figured out how to connect to the database and get back the resultset, but how do I loop through the recordset and build the table to display the query results on the page. The table will need to have 6 columns, and I obviously don't know how many rows, it will depend on the date range.

Thanks,
Mike T.

6 replies

by jay eckles

Response.Write( "

" )
Do While Not RecordSet.EOF
Response.Write( "

" )
Response.Write( "

" )
'continue to fill other five cells in similar fashion
Response.Write( "

" )
RecordSet.MoveNext
Next
Response.Write( "

" )
Response.Write( RecordSet("field1") )
Response.Write( "

" )

'good luck. Jay Eckles

by miket

Thanks very much for your reply. Very clean and straightforward.

Mike T.

by bob reimer

This will print a header row and then your dataset without having to know the number of columns in advance:

Set rs = Recordset 'what you've populated already
Set flds = rs.Fields
Response.Write "

"
j = flds.Count - 1
For i = 0 to j Response.Write "

"
Next i
Response.Write "

"
Set flds = Nothing
Do Until rs.EOF
Response.Write "

"
For i = 0 to j
Response.Write "

"
Next i
Response.Write "

"
rs.MoveNext
Loop

" & flds(i).Name & "
" & rs.Fields(i).Value & "

by miket

Thanks very much for your reply. Very clean and straightforward.

Mike T.

This discussion is closed to new replies.