本地服务器数据库 testdb
表 title1
name urlname id
---------- -------------------- ----------
a ./x.asp 1
b ./a.asp 2
c ./j.asp 3
d ./p.asp 4
e ./n.asp 5
f ./k.asp 6 g ./lx.asp 7
表 title2
name urlname id id2
-------------------------------------------------- -------------------------------------------------- ---------- ----------
b1 ./g.asp 2 21
b2 ./h.asp 2 22
b3 ./y.asp 2 23
b4 ./l.asp 2 24
c1 ./h.asp 3 31
c2 ./s.asp 3 32
c3 ./x.asp 3 33
d1 ./z.asp 4 41
d2 ./k.asp 4 42
d3 ./g.asp 4 43
d4 ./c.asp 4 44
d5 ./x.asp 4 45
asp 连接文件
<%
set cn = Server.CreateObject("ADODB.Connection")
cnstr="Provider=SQLOLEDB.1;Data Source=(local);User ID=sa;Password=;Database=testdb;"
on error resume next
cn.open cnstr
if err.number <> 0 then
response.redirect("err.asp?xx=不能连接数据库,可能是WEB数据库服务器没有启动")
end if
%>
asp 数据需求文件
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title></title>
<!--#include file="conn.asp"-->
<%
set rs=server.CreateObject("adodb.recordset")
rs.open"select * from title1",cn,1,1
%>
<style type="text/css">
<!--
body {
margin-left: 0px;
margin-top: 0px;
margin-right: 0px;
margin-bottom: 0px;
}
-->
</style>
</head>
<body>
<table width="100%" border="0">
<tr>
<th align="left" bgcolor="#666699" scope="col">
<%
do while not rs.eof
%>
<a href="<%=rs("urlname")%>" target="_self"><%= rs("name") %></a><br>
<% idStr = rs("id")
set rs1=server.CreateObject("adodb.recordset")
rs1.open "SELECT * FROM title2 WHERE id = '"&idStr&"'",cn,1,1
if rs1<>NaN then
%>
<%
do while not rs1.eof
%>
<a href="<%=rs1("urlname")%>" target="_self"><%= rs1("name") %></a><br>
<%
rs1.movenext
loop
%>
<%
rs1.close
%>
<% end if %>
<%
rs.movenext
loop
%>
<% rs.close %>
<% cn.close %> </th>
</tr>
</table>
</body>
</html>
结果
a
b
b1
b2
b3
b4
c
c1
c2
c3
d
d1
d2
d3
d4
d5
e
f
g