记录集横向换行显示

来源:百度知道 编辑:UC知道 时间:2024/06/02 11:55:00
<%@LANGUAGE="VBSCRIPT"%>
<!--#include file="Connections/webb.asp" -->
<%
Dim Recordset1
Dim Recordset1_numRows

Set Recordset1 = Server.CreateObject("ADODB.Recordset")
Recordset1.ActiveConnection = MM_webb_STRING
Recordset1.Source = "SELECT * FROM guochanproductsort1"
Recordset1.CursorType = 0
Recordset1.CursorLocation = 2
Recordset1.LockType = 1
Recordset1.Open()

Recordset1_numRows = 0
%>
<%
Dim Repeat1__numRows
Dim Repeat1__index

Repeat1__numRows = -1
Repeat1__index = 0
Recordset1_numRows = Recordset1_numRows + Repeat1__numRows
temp = 0%>
<table width="220" border="1">
<tr>
<td><%
While ((Repeat1__numRows <> 0) AND (NOT Recordset1.EOF))
%>
<%=(Recordset1.Fields.Item("name").Value)%>

将Dim Repeat1__numRows
......
</table><%
的代码换为如下:

Dim tblstr, j, k
If Recordset1.RecordCount Mod 3 = 0 Then
j = Recordset1.RecordCount
Else
j = Recordset1.RecordCount + 3 - (Recordset1.RecordCount Mod 3)
End If
k = 1
Recordset1.MoveFirst
tblstr = "<table width='220' border='1'> "
While (k <= j)
tblstr = tblstr & "<tr>"
For i = 1 To 3
If k <= Recordset1.RecordCount Then
tblstr = tblstr + "<td>" & Recordset1.Fields.Item("name").Value & "</td>"
Else
tblstr = tblstr + "<td>空位</td>"
End If
k = k + 1
If Not Recordset1.EOF Then Recordset1.MoveNext
Next
tblstr = tblstr & "</tr>"

Wend
tblstr = tblstr & "</table>"

response.write tblstr

a