朋友缘分的句子经典:aso sql语言查询问题

来源:百度文库 编辑:中科新闻网 时间:2024/04/29 23:29:05
<%
set dbconnection=Server.CREATEOBJECT("ADODB.CONNECTION")
DBPath = Server.MapPath("../data/systemdata.mdb")
dbconnection.Open "driver={Microsoft Access Driver (*.mdb)};dbq=" & DBPath
SQL="select * from student,choose_course where (choose_course.teachername='"+Session("teachername")+"')and (choose_course.studentid=student.studentid)"
set mystu=dbconnection.execute(SQL)
studentid=mystu("studentid")
studentname=mystu("studentname")
sex=mystu("sex")
collage=mystu("collage")
phonenumber=mystu("phonenumber")
email=mystu("email")
birthday=mystu("birthday")

%>

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>myclass</title>
<style type="text/css">
<!--
body {
margin-top: 0mm;
}
body,td,th {
font-size: 14px;
}
-->
</style></head>

<body>
<table width="618" border="0" align="center" cellspacing="1" bgcolor="#ffffcc">
<tr>
<td><font color="blue"><b>学号<b></font></td><td><font color="blue"><b>姓名<b></font></td><td><font color="blue"><b>性别<b></font><td><td><font color="blue"><b><font color="blue"><b>学院<b></font></td><td><font color="blue"><b>电话<b></font></td><td><font color="blue"><b>email<b></font></td><td><font color="blue"><b>生日<b></font></td>
</tr>
<% DO WHILE NOT mystu.EOF %>
<TR>
<td><%=studentid%></td><td><%=studentname%></td><td><%=sex%><td><td><%=collage%></td><td><%=phonenumber%></td><td><%=email%></td><td><%=birthday%></td>
</tr>
<% mystu.movenext
loop
%>
</table>
</body>
</html>

我想根据条件显示表:student 中学生的信息.条件是:根据两个表连接的,我想显示的是根据表choose_course中teachername='"+Session("teachername")+"')而得到该表中符合条件的studentid再显示表student中与之对应studentid的所有学生信息. 但是为什么显示的都是同一条信息呢?如符合条件是有10条,但这10条都只显示排在前面的一条的!
希望有人帮我看看代码要怎样改?谢谢

改过了:

<%
set dbconnection=Server.CREATEOBJECT("ADODB.CONNECTION")
DBPath = Server.MapPath("../data/systemdata.mdb")
dbconnection.Open "driver={Microsoft Access Driver (*.mdb)};dbq=" & DBPath
SQL="select * from student,choose_course where (choose_course.teachername='"+Session("teachername")+"')and (choose_course.studentid=student.studentid)"
set mystu=dbconnection.execute(SQL)
%>

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>myclass</title>
<style type="text/css">
<!--
body {
margin-top: 0mm;
}
body,td,th {
font-size: 14px;
}
-->
</style></head>

<body>
<table width="618" border="0" align="center" cellspacing="1" bgcolor="#ffffcc">
<tr>
<td><font color="blue"><b>学号<b></font></td><td><font color="blue"><b>姓名<b></font></td><td><font color="blue"><b>性别<b></font><td><td><font color="blue"><b><font color="blue"><b>学院<b></font></td><td><font color="blue"><b>电话<b></font></td><td><font color="blue"><b>email<b></font></td><td><font color="blue"><b>生日<b></font></td>
</tr>
<%
DO WHILE NOT mystu.EOF

studentid=mystu("studentid")
studentname=mystu("studentname")
sex=mystu("sex")
collage=mystu("collage")
phonenumber=mystu("phonenumber")
email=mystu("email")
birthday=mystu("birthday")
%>
<TR>
<td><%=studentid%></td><td><%=studentname%></td><td><%=sex%><td><td><%=collage%></td><td><%=phonenumber%></td><td><%=email%></td><td><%=birthday%></td>
</tr>
<% mystu.movenext
loop
%>
</table>
</body>
</html>