从两个表中提取数据的问题

liwan123 2003-08-22 03:34:57
我做了一个留言本,是个大家都可以回复的。建了两个表,一个假如是db(含id,name,oicq,content字段),以id作为主关键字而且是自动编号,另一个表是reply(含replyid,name,answer字段)。replyid与id相同,则reply中的纪录既为回复的纪录。现在是我回复字段都能写到reply表中,但我在首页调用reply中的纪录却不显示,不知道是什么原因。看看个位高手是怎么样从两个表中调用数据的啊
...全文
62 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
kjeny2002 2003-08-22
  • 打赏
  • 举报
回复


select id.name,id.oicq,id.content,reply.repyid,reply.name,reply.answer from id,reply;

二个表里的记录都查出来了。

要方便一点的话就按楼上的。

先查一个表,再根据这个表中的某个字段(比如ID)作为条件查另一个表

tigerwen01 2003-08-22
  • 打赏
  • 举报
回复
可能ID号不对应。在回复是把db表中相应的ID写入reply表中,取出时只需取reply表中相应的ID的记录。例:
<%
...
dim sql,reRs

Set reRs=Server.CreateObject("ADODB.RecordSet")
sql="select * from Tb_Ainfo where A_Qid="&Request("id")
reRs.open sql,oConn,1,3
if reRs.bof and reRs.eof then
Response.Write ""
else
Do while not reRs.eof
%>
<tr>
<td width="100%" colspan="3" height="18">
<p align="center"><font size="2" color="#008000">作者:</font><font size="2" color="#3399FF"><%=reRs("A_Author")%></font>    <font size="2" color="#008000">回复时间:</font><font size="2" color="#3399FF"><%=reRs("A_Time")%></font></p>
</td>
</tr>
<tr bgcolor=#EBEBEB>
<td width="100%" colspan="3" height="18">    <%
Dim reCont
reCont=reRs("A_Contents")
reCont=Replace(reCont,vbcrlf,"<br>   "&vbcrlf)
Response.Write reCont
%></td>
<%
reRs.MoveNext
Loop
end if
set reRs=nothing
%>
ttt2 2003-08-22
  • 打赏
  • 举报
回复
<%
set rs=server.createobject("adodb.recordset")
rs.open "select * from db",cn,1,3
ser rsp=server.createobject("adodb.recordset")

while not rs.eof
rsp.open "select * from reply where replyid="&rs("id"),cn,1,3
while not rsp.eof
''操作
rsp.movenext
wend
rsp.close


rs.movenext
wend

28,390

社区成员

发帖
与我相关
我的任务
社区描述
ASP即Active Server Pages,是Microsoft公司开发的服务器端脚本环境。
社区管理员
  • ASP
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧