Dynamic | Web page
Sometimes, you need to put a certain number of words and pictures in a table column, and need to dynamically display the number of rows and columns, such as 4 pictures in a row or 5 pictures, sometimes it is difficult to judge the end of TR or TD with a table, where I wrote a piece of code, Can judge the end position of the ranks in real time, and automatically add the empty TR and TD when the data in the recordset is insufficient.
Test table
' Create Table Test (ID int,stitle varchar (50))
Program code
' Test row 4 columns, row four rows
Dim i,j
Dim irscount,irows
Dim perlines
Perlines=4 ' Number of columns to display per line
Set Objrs=server. CreateObject ("Adodb.recordset")
Objrs.open "SELECT top * from Test ORDER by id", conn,3,1
If not objrs.eof Then
Response.Write "<table width=" "100%" "cellpadding=" "0" "cellspacing=" "8" ">" &vbcrlf
Irscount=objrs.recordcount ' Get the actual number of records
Irows=int (Irscount/perlines) ' calculates the number of rows available
If Irows<1 Then
Irows=1
Else
If Irscount mod perlines=0 then
Irows=int (Irscount/perlines)
Else
Irows=int (Irscount/perlines) +1
End If
End If
I=1
While Not objrs.eof
For I=1 to Irows
Response.Write "<tr>" &vbcrlf
For J=1 to Perlines
If Not objRS.EOF Then
Response.Write "<td width=" "25%" "><div align=" "Center" ">" &objrs ("Stitle") & "</div></" Td> "&vbcrlf
Else
Response.Write "<td> </td>" &vbcrlf
End If
If not objrs.eof then Objrs.movenext
Next
Response.Write "</tr>" &vbcrlf
Next
Wend
Response.Write "</table>"
End If
Objrs.close
Set objrs=nothing