ASP一个关于循环判断的问题

来源:百度知道 编辑:UC知道 时间:2024/05/22 18:36:51
一个关于电影剧照欣赏的页面.现在数据库里有两个表,一个电影表是movie,里面有字段id,title(电影名);还有一个剧照表是photo,字段有id,mid(就是movie表里的id),title(电影名),showimage(图片名)。要注意一点,并不是每部电影都有剧照。
现在需要的效果是:读出每一部有剧照的电影名称,并附上剧照,每一行放三条电影。

不知道哪位高手能帮帮忙?
一部影片可能会有N张剧照,但只需要读其中一张剧照.是根据电影来排序的.就是有多少部有剧照的电影就读多少条,而每部电影只对应一张剧照/

以下页面代码是根据你的需求量身定做的,已测,时间关系未做页面布局优化,未写注释,还望你多多练习,大家今后相互勉励!
<!--#include file="conn.asp"-->
<table width="776" border="1" align="center" cellpadding="0" cellspacing="0">
<%
dim sql,sql_count,rs,rs_count,max_num,max,i,j

sql="select title,showimage from photo where id in(select min(id) from photo group by mid)"
set rs=conn.execute(sql)

sql_count="select count(title) from movie where title in(select distinct title from photo where showimage is not null)"
set rs_count=conn.execute(sql_count)

max_num=rs_count(0)
max=int(max_num/3)
for i=0 to max
%>
<tr>
<%for j=0 to 2%>
<td align="center">Movie Name:<%=rs(0)%><br>Photo Name:<%=rs(1)%></td>
<%rs.movenext%>
<%if rs.EOF then
j=j+1
Exit For
end if%&