asp循环输出表格问题

王朝知道·作者佚名  2012-09-24
窄屏简体版  字體: |||超大  
 
分類: 電腦/網絡 >> 程序設計 >> 其他編程語言
 
問題描述:

<table border="1" cellpadding="0" align="right" cellspacing="0">

<%

dim a,b

b=0

sql="select * from chanpin order by id DESC"

set rs=server.createobject("adodb.recordset")

rs.open sql,conn,1

do

response.Write "<tr>"

For a = 1 to 3

if not rs.eof and not rs.bof then

image = "<table width='164' height='142' border='0' cellpadding='0' cellspacing='0'><tr> <td width='164' height='111'><div align='center'><img height=97 src='"&rs("img")&"' width=117></div></td></tr><tr><td>[名称]:"&rs("biaoti")&"</td></tr><tr> <td>[型号]:"&rs("guige")&"</td></tr></table>"

else

image = " "

end if

%>

<td width="165" height="144"><%=image%></td>

<%

rs.movenext

Next

response.Write "<tr>"

b=b+1

rs.movenext

if b=2 then

exit do

end if

loop

%>

</table>

就是输出一个 两行三列的表格 如果数据库没有记录了就输出空表格 我这里测试 输出 3个 5个 6个 都没有问题 要是输出1 2 4 就有问题了

谢谢回复

參考答案:

<table>

<%

cell_num=3

Control_num=0

do while not rs.eof

if Control_num mod cell_num=0 then

Response.write "<tr>"

end if

Response.write "<td>"&rs(0)&?"</td>"

if Control_num mod cell_num=0 then

Response.write "</tr>"

end if

control_num=control_num+1

rs.movenext

loop

%>

</table>

利用模来控制换行,例子给你了,看懂了自己照着改!你的程序错误在于rs.movenext后,没有检测是否rs.eof

小贴士:① 若网友所发内容与教科书相悖,请以教科书为准;② 若网友所发内容与科学常识、官方权威机构相悖,请以后者为准;③ 若网友所发内容不正确或者违背公序良俗,右下举报/纠错。
 
 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
 
 
© 2005- 王朝網路 版權所有 導航