日期:2014-05-17  浏览次数:20854 次

从数据库中读取数据,实现自动换行
我从数据库中读取字段“姓名”,每行显示4个,依次显示怎么做?
========================================
<table   width= "1000 "   border= "0 "   cols= "4 "> <tr>
<%   dim   rs
      set   rs   =   Server.CreateObject( "ADODB.recordset ")
      sqltex= "select   *   from   人物志 "

      rs.Open   sqltex,conn,1,1
      do   while   not   rs.eof   or   rs.bof
%>
<td   width= "200 "> <%=rs( "姓名 ")%> </td>
<%
    rs.movenext
    loop
    set   rs=   nothing
    set   conn=nothing
%> </tr>
</table>

------解决方案--------------------
<table width= "1000 " border= "0 " cols= "4 "> <tr>
<% dim rs
set rs = Server.CreateObject( "ADODB.recordset ")
sqltex= "select * from 人物志 "

rs.Open sqltex,conn,1,1
do while not rs.eof or rs.bof
%>
<tr>
<%for i=1 to 4%>
<td width= "200 "> <%=rs( "姓名 ")%> </td>
<%
rs.movenext
next
%>
</tr>
<%
loop
set rs= nothing
set conn=nothing
%> </tr>
</table>

------解决方案--------------------
<table width= "1000 " border= "0 " cols= "4 "> <tr>
<% dim rs
set rs = Server.CreateObject( "ADODB.recordset ")
sqltex= "select * from 人物志 "

rs.Open sqltex,conn,1,1
dim i
i=0
do while not rs.eof or rs.bof
i=i+1

%>
<td width= "200 "> <%=rs( "姓名 ")%> </td>
<%if (i mod 4)=0 then
response.write " </tr> <tr> "
end if
rs.movenext
loop
set rs= nothing
set conn=nothing
%> </tr>
</table>

------解决方案--------------------
<table width= "1000 " border= "0 " cols= "4 "> <tr>
<% dim rs,i
i=1
set rs = Server.CreateObject( "ADODB.recordset ")
sqltex= "select * from 人物志 "

rs.Open sqltex,conn,1,1
do while not rs.eof or rs.bof
%>
<td width= "200 "> <%=rs( "姓名 ")%> </td>
<%if i mod 4=0 then
response.write " </tr> <tr> "
end if
i=i+1
rs.movenext
loop
set rs= nothing
set conn=nothing
%> </tr>
</table>
-----------------------------
上面是一种方法,通过变量来判断,还有一种方法是能过css样式表来控制。