<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