<%
dim connect, rs, sql, outrec, aid
set connect = server.createobject("ADODB.Connection")
connect.open("DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=" &_
Server.MapPath("\perlphpasp\db\casereg.mdb"))
sql = "select first(student.advid) as aid, first(atname) as aname,"
sql = sql + "count(idstd) as cnt from student,advisor "
sql = sql + "where student.advid = advisor.advid group by student.advid"
set rs = connect.execute(sql)
response.write("<body><form action=groupadv.asp method=post>")
response.write("<select name=gp size=5>")
rs.movefirst
do while not rs.eof
outrec = rs("aid")&" "&rs("aname")&" have advisee : "&rs("cnt")&"<br>"
response.write("<option value="&rs("aid")&">"&outrec)
rs.movenext
loop
response.write("</select><input type=submit name=action value=select></form>")
if request.form("action") = "select" then
gpid = request.form("gp")
sql = "select * from student where advid="&gpid &" order by idstd"
set rs = server.createobject("ADODB.recordset")
rs.open sql,connect,1,3
totrs = rs.recordcount
rs.movefirst
for i = 1 to totrs
response.write(i&". "&rs("idstd")&" "&rs("stname")&"<br>")
rs.movenext
next
end if
connect.close
set rs = nothing
set connect = nothing
%>
จำนวน : 34 บรรทัด