An algorithm for ASP output table

Source: Internet
Author: User
Tags end

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 = " " & 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 = " " & str & "
"
End If

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.