我是asp的新手,在从数据库中取数据做循环时,出现问题:共有3个表:a,b,c a表:a_id,a_name;b表:b_id,b_name,a_id;c表:c_id,c_name,a_id;
我要先从a表中取出数据,根据a表的a_id从b,c表取出相关数据,a表数据取出成功并显示出来;b,c表数据显示成功取出,但不能显示出来,求各位帮帮看看:
我将源码显示如下:
<!--#include file="conn.asp"-->
<SCRIPT LANGUAGE=javascript>
var tt='start';
var ii='start';
function turnit(ss,bb) {
if (ss.style.display=="none") {
if(tt!='start') tt.style.display="none";
if(ii!='start') ii.src="";
ss.style.display="";
tt=ss;
ii=bb;
bb.src="";
}
else {
ss.style.display="none";
bb.src="";
}
}
</SCRIPT>
<table border="0" cellspacing="1" cellpadding="4" bgcolor="#FFFFFF" align="center" width="100%">
<%
set rs=server.CreateObject("adodb.recordset")
sql="SELECT a_id,a_name FROM a"
rs.open sql,conn, 1, 1
%>
<tr class=classtop1>
<td height="15" align="center">a_id</td>
<td height="15" align="center">a_name</td>
</tr>
<%if rs.eof and rs.bof then
response.write "还没有数据,请添加!"
Else
do while not rs.eof%>
<tr>
<td class="classtd" id=tag<%=rs("a_id")%> style='CURSOR: hand' onclick=turnit(Content<%=rs("a_id")%>,tag<%=rs("a_id")%>); language=JScript>
<%=rs("a_id")%>
</td>
<td class="classtd" align="center">
<%=rs("a_name")%>
</td>
</tr>
<tr>
<td colspan="10" align="right" height="50" id=Content<%=rs("a_id")%> style='DISPLAY: none'>
<table align=center width="667">
<%
set rsl=server.CreateObject("adodb.recordset")
sqll="SELECT a_id,b_id,b_name FROM b where a_id="&rs("a_id")
'response.write sqll
rsl.open sqll,conn, 1, 1
%>
<tr><td align= center>b_id</td>
<td align="center">
b_name</td>
</tr>
<%if rsl.eof and rsl.bof then
response.write "还没有数据,请添加!"
Else
do while not rsl.eof%>
<tr>
<td align= center><%rsl("b_id")%></td>
<td align="center">
<%rsl("b_name")%></td>
</tr>
<%
rsl.movenext
loop
end if
rsl.close
set rsl=Nothing
%> </table>
<table align=center width="669">
<%
set rsy=server.CreateObject("adodb.recordset")
sqly="SELECT a_id,c_id,c_name FROM c where a_id="&rs("a_id")
'response.write sqly
rsy.open sqly,conn, 1, 1
%>
<tr><td align= center>c_id</td>
<td align="center">
c_name</td>
</tr>
<%if rsy.eof and rsy.bof then
response.write "还没有数据,请添加!"
Else
do while not rsy.eof%>
<tr><td align= center><%rsy("c_id")%></td>
<td align="center">
<%rsy("c_name")%></td>
</tr>
<%
rsy.movenext
loop
end if
rsy.close
set rsy=Nothing
%> </table>
</td></tr>
<%
rs.movenext
loop
End If
rs.close
set rs=Nothing
%>