Table output Database results are often the case, the table has multi-layer structure, the outer layer is table again set TR (actually have tbody), and then set TD, the TD may interact with each other, so the study of ASP output table algorithm is still more interesting.
Table is the outermost element, do not loop, use is relatively simple, first look at only one column of the table example, we use the RecordSet object RS as the data source, the resulting results are stored in Str.
Dim str
str = ""
Do as not rs.eof
str = str & "" & RS ("FLD") & ""
Rs. MoveNext
Loop
If str <> "" Then
str = "
"
End If
The case of a column is very simple, there is no point of view, multiple columns are much more complex, in this example we use an array as the data source. Primarily consider the beginning of a line, the end of a line, and the column that supplements the last row.
Dim arr (3)
Arr (0) = 1
Arr (1) = 2
Arr (2) = 3
Arr (3) = 4
Maximum number of columns in Dim maxcolscnt ' line
MAXCOLSCNT = 3
Dim colscnt ' How many columns have been generated in total
colscnt = 0
Dim str
str = ""
Dim i
i = 0
Do While I<=ubound (arr)
If colscnt mod maxcolscnt = 0 Then
' Start of line
str = str & ""
End If
str = str & "" & Arr (i) & ""
colscnt = colscnt + 1
If colscnt mod maxcolscnt = 0 Then
' End of line
str = str & ""
End If
i = i + 1
Loop
If colscnt mod maxcolscnt <> 0 Then
' Add the last row of columns
Do While colscnt mod maxcolscnt <> 0
str = str & " "
colscnt = colscnt + 1
Loop
str = str & ""
End If
If colscnt > 0 Then
str = "
"
End If