如何根据库中一个表的字段id号显示另一个表的相关字段?
我的问题是:在下面一段网页代码中如何根据不同news信息的newsid值在前台正确地显示出type表及border表中的typename和bordername值,即<%=sql1%>、<%=sql1%>的文字信息?(数据库为access,其中有三个表type、border、news,各表的字段有type:typeid、typename;border:borderid、typeid、bordername;news:newsid、typeid、borderid……他们相互关联),请各位高手指教!如何根据各条信息的newsid号在数据库中的type表和border表中提取出对应的typename和bordername并在前台显示(如代码中的<%=sql1%>、<%=sql2%>)?代码如下:<%
dim sql,rs,rsc,thedate,borderid,typeid,sql2,sql1
set rs=server.createobject("adodb.recordset")
sql="update news set hits=hits+1 where newsid=" & cstr(request("newsid"))
conn.execute sql
if session("purview")="" then
rs.open "select * from news where newsid=" & cstr(request("newsid")) & " and audit=1",conn,1,1
else
rs.open "select * from news where newsid=" & cstr(request("newsid")),conn,1,1
if not rs.bof and not rs.eof then
typeid=rs("typeid")
borderid=rs("borderid")
end if
rs.close
rs.open "select bordername from border where borderid=" & borderid &" and typeid=" & typeid &"",conn,1,1
if not rs.bof and not rs.eof then
sql2=rs("bordername")
end if
rs.colse
rs.open "select typename from type where typeid=" & typeid &"",conn,1,1
if not rs.bof and not rs.eof then
sql1=rs("typename")
end if
end if
if err.number <> 0 then
response.write "数据库出错"
else
if rs.bof and rs.eof then
rs.close
response.write "该信息不存在或未经过审核"
else
%>
<HTML>
<HEAD>
<TITLE><%=rs("topic")%></TITLE>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
</head>
<body text="#000000" leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">
<table width="998" border="0" cellpadding="0" cellspacing="0" height="22">
<!--DWLayoutTable-->
<tr><TD width="998" height="30" valign="middle" style="FILTER: progid:DXImageTransform.Microsoft.Gradient(startColorStr='#E9E9E9', endColorStr='#FFFFFF', gradientType='1')"> 网络位置:<A href="index.asp" class="z1">首页</A> >> <%=sql1%> >> <%=sql2%> >> 详细内容</TD></td></tr></table>
</body>
</HTML>