这个循环问题要如何解决?

dandanlovelove 2009-08-06 01:29:44


<%sub hotel_hots(pic,num)%>
<%theclass=3%>
<table width="250" height="40" border="0" cellpadding="0" cellspacing="0" class="tb1">

<tr>
<td align="center" valign="top">

<%if pic=1 then%>
<table width="240" border="0" cellpadding="0" cellspacing="0">
<%
sql_top="select top 1 * from hotel where op_type like '%"&theclass&"%' order by hots asc,id desc "
set rs_top=Server.CreateObject("ADODB.Recordset")
rs_top.open sql_top,conn,1,1
if (rs_top.eof and rs_top.bof) then
response.write "<div align=center><p><font color=red>暂无任何信息</font></p></div>"
else%>
<%
if rs_top("star")=2 then
mystar="<img src='images/star1.gif'><img src='images/star1.gif'><img src='images/star1.gif'><img src='images/star1.gif'><img src='images/star2.gif'>"
end if
if rs_top("star")=3 then
mystar="<img src='images/star1.gif'><img src='images/star1.gif'><img src='images/star1.gif'>"
end if
if rs_top("star")=4 then
mystar="<img src='images/star1.gif'><img src='images/star1.gif'><img src='images/star1.gif'><img src='images/star2.gif'>"
end if
%>
<%
do while not rs_top.eof
sql="select x_price,name from Hotel_Price where HotelID="&rs_top("ID")&" order by x_price asc"
set pricers=conn.execute(sql)
if not pricers.eof then
hprice2=pricers("x_price")
hroom=pricers("name")
else
hprice2="--"
hroom="--"

end if
%>
<tr align="center">
<%
sql_top_1="select top 12 * from hotel where op_type like '%"&theclass&"%' order by hots asc,id desc"
set rs_top_1=Server.CreateObject("ADODB.Recordset")
rs_top_1.open sql_top_1,conn,1,1
if (rs_top_1.eof and rs_top_1.bof) then
response.write "<td height=30>暂无内容</td>"
else
n=0
do while not rs_top_1.eof
n=n+1
if n=1 then
id1=rs_top_1("id")
end if
if n=4 then
id2=rs_top_1("id")
end if
%>

<td width="50%"><table width="20" height="20" border="0" cellspacing="0" class="tb4">

<tr>
<td><a href="../hotel/show.asp?id=<%=rs_top_1("id")%>" target="_blank" title="<%=rs_top_1("name")%>"><img src="../hotel/top/<%=rs_top_1("url")%>" width="99" height="68" border="0" /></a></td>
</tr>
<tr>
<td><a href="show.asp?id=<%=rs_top_1("id")%>" target="_blank"><%=rs_top_1("name")%></a></td>
</tr>
<tr>
<td>星级:<%=mystar%></td>
</tr>
<tr>
<td>价格:¥<%=hprice2%></td>
</tr>
<tr>
<td>位置:<%=rs_top("address")%></td>
</tr>
</table></td>
<%if n mod 4=0 then response.write("</tr><tr align=center>")
rs_top_1.movenext
loop
end if
rs_top_1.close
set rs_top_1=nothing%>

</tr>
</table>

<%
rs_top.movenext
loop
%>

<%
end if
rs_top.close
set rs_top=nothing%>
<%end if%>
</td>
</tr>
</table>
<table width="80%" height="10" border="0" cellpadding="0" cellspacing="0">
<tr>
<td></td>
</tr>
</table>
<%end sub%>



只显示第一个酒店的星级价格和位置,如何解决?
...全文
73 4 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
cngothic 2009-08-07
  • 打赏
  • 举报
回复
那为什么不判断下 n = 1 时 输出 酒店的星级价格和位置。而其它都不显示。

不是说的很酒了吗?你要输出12个。但N = 1 只有一次是吧。N = 1 这个就是第一次循环也就是你想输出
酒店的星级价格和位置 的地方。
If N = 1 Then Response.Write("酒店的星级价格和位置")
dandanlovelove 2009-08-06
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 cngothic 的回复:]
你的代码太长了。
你都用到了循环也知道用n = n + 1来换行。

头一个酒店时 n = 1?
第二个酒店时 n = 2?
第三个酒店时 n = 3?
第三个酒店时 n = 4? n mod 4 = 0此时换行接着输出

那为什么不判断下 n = 1 时 输出 酒店的星级价格和位置。而其它都不显示。

希望你能看懂
[/Quote]
我要输出12个啊,判断如何写?
cngothic 2009-08-06
  • 打赏
  • 举报
回复
你的代码太长了。
你都用到了循环也知道用n = n + 1来换行。

头一个酒店时 n = 1?
第二个酒店时 n = 2?
第三个酒店时 n = 3?
第三个酒店时 n = 4? n mod 4 = 0此时换行接着输出

那为什么不判断下 n = 1 时 输出 酒店的星级价格和位置。而其它都不显示。

希望你能看懂
dandanlovelove 2009-08-06
  • 打赏
  • 举报
回复
不要抽象的答案,猜的我累翻了

28,409

社区成员

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

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