asp 循环显示问题求助

sufin 2013-04-07 09:05:08
<tr>
<td width="80" align="center"> </td>
<td width="130" align="center">组号</td>
<td width="130" align="center">值班领导</td>
<td width="500" align="center">值班人员</td>
<td align="center"> </td>
</tr>
<%
sql="select * from name"
Set rs= Server.CreateObject("ADODB.Recordset")
rs.open sql,conn,1,1
if rs.eof and rs.bof then
response.write "<p align=center class=font>暂无值班人员</p>"
else
dim x,y,z
x=1
do while not rs.eof
if x>=8 then
exit do
end if
if cint(rs("group"))=x then
if rs("lindao")=true then
y=rs("name")+y
end if
z=rs("name")+z
end if

%>
<tr>
<td width="80" align="center"> </td>
<td width="130" align="center">第<%=x%>组:</td>
<td height="130" width="300"><%=y%></td>
<td width="500" align="center" bgcolor="#F7F7F7"><%=z%></td>
<td align="center"> </td>
</tr>
<%
x=x+1
rs.MoveNext
loop
end if
set rs=nothing
%>

上面是代码
...全文
118 15 打赏 收藏 转发到动态 举报
写回复
用AI写文章
15 条回复
切换为时间正序
请发表友善的回复…
发表回复
net_php 2013-04-12
  • 打赏
  • 举报
回复
LZ学学基本的SQL语句啊,,,
  • 打赏
  • 举报
回复
你这种做法兼职多此一举,虽然能实现同样的效果
sufin 2013-04-09
  • 打赏
  • 举报
回复
<% for x=1 to 7 sql="select * from name where zu="&x Set rs= Server.CreateObject("ADODB.Recordset") rs.open sql,conn,1,1 if rs.eof and rs.bof then response.write "<p align=center class=font>暂无值班人员</p>" else do while not rs.eof if rs("lindao")=true then y=rs("name")+","+y else z=rs("name")+","+z end if rs.MoveNext loop %> <tr> <td width="80" align="center"> </td> <td width="130" align="center">第<%=x%>组:</td> <td width="130"><%=y%></td> <td width="500" align="center" bgcolor="#F7F7F7"><%=z%></td> <td align="center"> </td> </tr> <% end if y="" z="" set rs=nothing next %>
sufin 2013-04-09
  • 打赏
  • 举报
回复
其实我自己经解决了,写好了
  • 打赏
  • 举报
回复
<%
sql="select * from name order by group" 
Set rs= Server.CreateObject("ADODB.Recordset")
rs.open sql,conn,1,1
  if rs.eof and rs.bof then
       response.write "<p align=center class=font>暂无值班人员</p>"
   else
dim x,y,z
temp=0
x=1
do while not rs.eof
if temp<>rs("group") and temp>0 then
%>
<tr>
<td width="80" align="center"> </td>
<td width="130" align="center">第<%=x%>组:</td>
    <td height="130" width="300"><%=y%></td>
    <td width="500" align="center" bgcolor="#F7F7F7"><%=z%></td>
    <td align="center"> </td>
  </tr>
<%
x=x+1
end if
if temp<>rs("group") then
	temp=rs("group")
	if rs("lindao")=true then
		y=rs("name")
	else
		z=rs("name")
	end if
else
	if rs("lindao")=true then
		y=rs("name")+","+y
	else
		z=rs("name")+","+z
	end if
end if
%>
<%
rs.MoveNext
loop
end if
   set rs=nothing 
%>
然后里面代码部分做下判断转换即可
  • 打赏
  • 举报
回复
<%
sql="select * from name order by group" 
Set rs= Server.CreateObject("ADODB.Recordset")
rs.open sql,conn,1,1
  if rs.eof and rs.bof then
       response.write "<p align=center class=font>暂无值班人员</p>"
   else
dim x,y,z
temp=0
do while not rs.eof
if temp<>rs("group") and temp>0 then
%>
<tr>
<td width="80" align="center"> </td>
<td width="130" align="center">第<%=x%>组:</td>
    <td height="130" width="300"><%=y%></td>
    <td width="500" align="center" bgcolor="#F7F7F7"><%=z%></td>
    <td align="center"> </td>
  </tr>
<%
x=x+1
end if
if temp<>rs("group") then
	temp=rs("group")
	if rs("lindao")=true then
		y=rs("name")
	else
		z=rs("name")
	end if
else
	if rs("lindao")=true then
		y=rs("name")+","+y
	else
		z=rs("name")+","+z
	end if
end if
%>
<%
rs.MoveNext
loop
end if
   set rs=nothing 
%>
然后里面代码部分做下判断转换即可
  • 打赏
  • 举报
回复
用了do while 就不要用for to 原始,你原来的那个就可以的,直接把SQL语句改就行了,程序都不用改的 真无语你
y2012 2013-04-08
  • 打赏
  • 举报
回复
<%
dim x
for x=1 to 7
	sql="select * from name order by group" 
	Set rs= Server.CreateObject("ADODB.Recordset")
	rs.open sql,conn,1,1
	if rs.eof and rs.bof then
	   response.write "<p align=center class=font>暂无值班人员</p>"
	else
		dim y,z
		do while not rs.eof
			if cint(rs("group"))=x then
				if rs("lindao")=true then
				y=rs("name")+","+y
				else
				z=rs("name")+","+z
				end if
			end if
			rs.MoveNext
		loop
		%>
		<tr>
		<td width="80" align="center"> </td>
		<td width="130" align="center">第<%=x%>组:</td>
			<td width="130"><%=y%></td>
			<td width="500" align="center" bgcolor="#F7F7F7"><%=z%></td>
			<td align="center"> </td>
		  </tr>
	<%
		y=""
		z=""
	End if
next
%>
sufin 2013-04-08
  • 打赏
  • 举报
回复
奇怪的是 我即便不用for循环,do while 的代码手工执行7次 if cint(rs("group"))=x then x改成 234567结果显示还是跟上图一样, 帮帮我吧,头痛
sufin 2013-04-08
  • 打赏
  • 举报
回复
真像3楼说的,代码改了一下,可还是有问题
sql="select * from name order by group"
Set rs= Server.CreateObject("ADODB.Recordset")
rs.open sql,conn,1,1
if rs.eof and rs.bof then
response.write "<p align=center class=font>暂无值班人员</p>"
else
dim x
for x=1 to 7
do while not rs.eof
dim y,z
if cint(rs("group"))=x then
if rs("lindao")=true then
y=rs("name")+","+y
else
z=rs("name")+","+z
end if
end if
rs.MoveNext
loop
%>
<tr>
<td width="80" align="center"> </td>
<td width="130" align="center">第<%=x%>组:</td>
<td width="130"><%=y%></td>
<td width="500" align="center" bgcolor="#F7F7F7"><%=z%></td>
<td align="center"> </td>
</tr>
<%
next
end if
结果如下:
  • 打赏
  • 举报
回复
sql="select * from name order by group" 这样去查询 就会按1,2,3,4,5,6,7组这样排下来了
  • 打赏
  • 举报
回复
请根据group这个字段排序查询就好了,是不是领导你只要判断lindao这个字段
  • 打赏
  • 举报
回复
思路不难,是不是又要别人替你写代码啊。如果是学习的话,在程序流程控制思路上面应该着重多花些功夫练习,就不至于为这事犯难了。
sufin 2013-04-08
  • 打赏
  • 举报
回复
没人回答,专业的呢?
sufin 2013-04-07
  • 打赏
  • 举报
回复

表信息


显示结果,下面到第7组为止,都一样

求助,显示正确结果!第一组的显示到第一组,第五组到第五组,是领导的也显示到相应位置。
谢谢

28,391

社区成员

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

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