读取2个表数据后如何循环
2个表Subject题目 和 Result答案
首先读取Subject 的 题目SubjectName 然后 根据 Subject表的题号 SubjectNo 显示Result的匹配的正确答案
输出格式:
题目1
答案1
题目2
答案2
相关代码:
<table width= "100% " height= "69 " border= "0 " cellpadding= "0 " cellspacing= "0 "> <tr>
<td height= "69 "> <table width= "98% " border= "0 " align= "center ">
<tr>
<% set Rs=server.createobject( "adodb.Recordset ")
Rs.open "select * from Subject where SortNo= "&TopSortNo& " order by SubjectNo asc ",conn,1,1
do while not rs.eof %>
<td width= "3% "> <img src= "images/lt_menu01.gif " width= "18 " height= "21 " /> </td> <td width= "97% "> <span class= "hei_12 "> <input name= "SubjectNo " type= "hidden " value= " <%=rs( "SubjectNo ")%> " /> </span> <span class= "hei_12 "> <%=rs( "SubjectName ")%> </span> </td>
</tr>
</table>
<table width= "98% " border= "0 " align= "center ">
<% num=rs( "SubjectNo ")
set rs1=Server.CreateObject( "ADODB.RecordSet ")
Rs1.open "select * from Result where SubjectNo= "&num& " and TrueFalse=-1 and SortNo= "&TopSortNo& " order by ResultNo asc ",conn,1,1
do while not rs1.eof
%>
<tr> <td width= "7% " class= "hei13 "> 答案: </td> <td width= "93% "> <span class= "hong12 "> <%=rs1( "ResultName ")%> </span> </td> </tr> </table>
<% rs.movenext
loop
rs.close
%>
<%
rs1.movenext
loop
rs1.close
%> </td>
</tr>
</table>
------解决方案--------------------用一个SQL语句就可以实现:Select A.*,B.* from A left join B on A.SubjectNo = B.SubjectNo
------解决方案-------------------- <table width= "100% " height= "69 " border= "0 " cellpadding= "0 " cellspacing= "0 "> <tr>
<td height= "69 "> <table width= "98% " border= "0 " align= "center ">
<tr>
<% set Rs=server.createobject( "adodb.Recordset ")
Rs.open "select * from Subject where SortNo= "&TopSortNo& " order by SubjectNo asc ",conn,1,1
do while not rs.eof %>
<td width= "3%