请教如何控制表格中每列显示5个数据?(例如15个数据分3列显示!)

xunfengxxx 2008-04-16 08:18:25
从数据库库读出记录使得表格中每列显示5个数据?
附部分程序:(请高手帮忙实现!)
<table >
<%
j=1
sqlj="select * from 单位 where 类别='乡镇医院' order by 排序 asc"
set rsj=conn.execute(sqlj)
rsj.movefirst
%>
<% do while not rsj.eof %>

<%if j mod 5=0 then.....?


</table>
...全文
255 16 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
16 条回复
切换为时间正序
请发表友善的回复…
发表回复
luther1122 2008-04-20
  • 打赏
  • 举报
回复
<table >
<%
sqlj="select * from 单位 where 类别='乡镇医院' order by 排序 asc"
set rsj=conn.execute(sqlj)
for i=1 to (15+3-1)\3'此处注释 (15+3-1):15为每页记录数,3为每行列数,然后整除个每行列数
if rsj.eof then exit for
%>
<tr>
<%
for j=1 to 每页列数
if rsj.eof then exit for
%>
<td>....</td>
<%
rsj.movenext
next
%>
</tr>
<%
next
%>
</table>
lidong8667 2008-04-19
  • 打赏
  • 举报
回复
按照这个改咯,刚做出来的.
<table border="0">
<tr>
<%set rs=server.CreateObject("adodb.recordset")
rs.Open "select * from links order by linkidorder",conn,1,1
i = 1
do while not rs.EOF

%>
<td height=28>
<a href=<%=trim(rs("linkurl"))%> target=_blank ><font color=#000000><%=trim(rs("linkname"))%></font></a></td>

<%
if i mod 3 =0 then response.write"</tr><tr>"
rs.MoveNext
i = i+1
loop
rs.Close
set rs=nothing
%></td>
</tr>
</table>
jnwentao 2008-04-16
  • 打赏
  • 举报
回复
最简单的办法.....不能整除的话最后会空几个,用string补一下就行了
set ........
dim n,rowArr(4)'每列显示的数据数量从0开始计算
do while not rsj.eof
if IsEmpty(n) or n = ubound(rowArr) theN
n = 0
else
n = n + 1
end if
rowArr(n) = rowArr(n) & "<td>"&rsj(字段名称)&"</td>"
loop
response.write "<table width='100%' border='1'><tr>" & join(rowArr,"</tr><tr>") & "</tr></table>"
myvicy 2008-04-16
  • 打赏
  • 举报
回复
如果15条记录后还要分行则
<table > <tr> <td>
<%
cellrecord=5 '定义每列显示的数据
cols=3 '定义每行显示的列数
j=1
sqlj="select * from 单位 where 类别='乡镇医院' order by 排序 asc"
set rsj=conn.execute(sqlj)
rsj.movefirst
%>
<% do while not rsj.eof %>
<%=rsj("field")%>改这里可以控制具体显示的数据以及格式
<%if j mod cols*cellrecord=0 then%>
</td></tr><tr><td>
<%elseif j mod cellrecord=0 then%>
</td> <td>
<%end if%>

<%
j=j+1
rsj.movenext
loop
%>
</td> </tr> </table>
jikun6666 2008-04-16
  • 打赏
  • 举报
回复
学习了
myvicy 2008-04-16
  • 打赏
  • 举报
回复
看下9楼的
xunfengxxx 2008-04-16
  • 打赏
  • 举报
回复
假如有14条记录就分三显示
也就是说:
表格第一列5个数据
表格第二列5个数据
表格第三列4个数据
请问怎么用表格布局?
上面程序是分了3行来显示的.
myvicy 2008-04-16
  • 打赏
  • 举报
回复
<table > <tr><td>
<%
j=1
sqlj="select * from 单位 where 类别='乡镇医院' order by 排序 asc"
set rsj=conn.execute(sqlj)
rsj.movefirst
%>
<% do while not rsj.eof %>
<%=rsj("field")%>
<%if j mod 5=0 then%>
</td> <td>
<%end if%>

<%
j=j+1
rsj.movenext
loop
%>
</td></tr> </table>
这个显示一行,每列显示5个数据
myvicy 2008-04-16
  • 打赏
  • 举报
回复
啥意思?
显示几行?
myvicy 2008-04-16
  • 打赏
  • 举报
回复
<table > <tr>
<%
j=1
sqlj="select * from 单位 where 类别='乡镇医院' order by 排序 asc"
set rsj=conn.execute(sqlj)
rsj.movefirst
%>
<% do while not rsj.eof %>
<td> <%=rsj("field")%> </td>
<%if j mod 5=0 then%>
</tr> <tr>
<%end if%>

<%
j=j+1
rsj.movenext
loop
%>
</tr> </table>
这个每行5列,你把5改一下就可以变成你想要的啊.
xunfengxxx 2008-04-16
  • 打赏
  • 举报
回复

假如有14条记录就分三列显示
也就是说:
表格第一列5个数据
表格第二列5个数据
表格第三列4个数据
请问怎么用表格布局?
上面程序是分了3行来显示的.
xunfengxxx 2008-04-16
  • 打赏
  • 举报
回复
都不对啊
!
好象在表格中一列再加几行比较难哦!
hookee 2008-04-16
  • 打赏
  • 举报
回复
<table> 
<%
n = 1
sql = "select * from 单位 where 类别='乡镇医院' order by 排序 asc"
set rs = conn.execute(sql)
do while not rsj.eof
if n mod 5 = 1 Then Response.Write "<tr>"
%>
<td><%=rs(0)%></td>
<%
if n = rs.RecordCount And n mod 5 <> 0 Then
For k=1 To 5-(n Mod 5)
Response.Write "<td></td>"
Next
Response.Write "</tr>"
End If
if n mod 5 = 0 Then Response.Write "</tr>"
n = n + 1
rs.MoveNext
loop
%>
</table>
jnwentao 2008-04-16
  • 打赏
  • 举报
回复
字段与格式写出来看看
列如:
单位 乡镇医院 ...
x1 x2 x3

还是
单位 x1
乡镇医院 x2
.... x3
myvicy 2008-04-16
  • 打赏
  • 举报
回复
<table > <tr>
<%
j=1
sqlj="select * from 单位 where 类别='乡镇医院' order by 排序 asc"
set rsj=conn.execute(sqlj)
rsj.movefirst
%>
<% do while not rsj.eof %>
<td> <%=rsj("field")%> </td>
<%if j mod 5=0 then%>
</tr> <tr>
<%end if%>

<%
j=j+1
rsj.movenext
loop
%>
</tr> </table>
myvicy 2008-04-16
  • 打赏
  • 举报
回复
<table > <tr>
<%
j=1
sqlj="select * from 单位 where 类别='乡镇医院' order by 排序 asc"
set rsj=conn.execute(sqlj)
rsj.movefirst
%>
<% do while not rsj.eof %>
<td><%=rs("field")%></td>
<%if j mod 5=0 then%>
</tr><tr>
<%end if%>

<%
j=j+1
rs.movenext
loop
%>
</tr></table>

28,409

社区成员

发帖
与我相关
我的任务
社区描述
ASP即Active Server Pages,是Microsoft公司开发的服务器端脚本环境。
社区管理员
  • ASP
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧