注册 登录
编程论坛 ASP技术论坛

读二张表其中一个不会循环

a190066 发布于 2010-08-15 20:30, 640 次点击
读二张表其中一个不会循环。字段:ok1可据ID循环,但表2 字段:ok2 只是循环了第一个ID的数据。请高手指点。谢谢!
表1:users1 字段:ok1   表2:users2  字段:ok2   
<%
 if request("dj")<>"" then
sql="select * from users1 where userid="&request("dj")&" order by id asc"
else
sql="select * from users1  order by id asc"
end if
 Set rs= Server.CreateObject("ADODB.Recordset")
 rs.open sql,conn,1,1
 set rs1=server.createobject("adodb.recordset")
sql1="select * from users2 order by id asc"
rs1.open sql1,conn,1,1
 
  if rs.eof and rs.bof then
       response.write "<p align='center'> 还 没 有 任 何 记 录</p>"
   else
      totalPut=rs.recordcount
      totalPut=rs.recordcount
      if currentpage<1 then
          currentpage=1
      end if
      if (currentpage-1)*MaxPerPage>totalput then
       if (totalPut mod MaxPerPage)=0 then
         currentpage= totalPut \ MaxPerPage
       else
          currentpage= totalPut \ MaxPerPage + 1
       end if

      end if
       if currentPage=1 then
           showpage totalput,MaxPerPage,"index.asp"
            showContent
            showpage totalput,MaxPerPage,"index.asp"
       else
          if (currentPage-1)*MaxPerPage<totalPut then
            rs.move  (currentPage-1)*MaxPerPage
            dim bookmark
            bookmark=rs.bookmark
           showpage totalput,MaxPerPage,"index.asp"
            showContent
             showpage totalput,MaxPerPage,"index.asp"
        else
            currentPage=1
           showpage totalput,MaxPerPage,"index.asp"
           showContent
           showpage totalput,MaxPerPage,"index.asp"
          end if
       end if
   end if
   sub showContent
       dim i
       i=0

  %>

<div align="center">
<table border="1" width="100%" id="table1" style="border-collapse: collapse">
    <tr>
        <td>id</td>
        <td>产品1</td>
        <td>产品2</td>
    </tr>
    <tr>
<%do while not rs.eof%>
        <td><%=rs("id")%></td>
        <td><%=rs("ok1")%></td>
        <td><%=rs1("ok2")%></td>
    </tr>

<% i=i+1
          if i>=MaxPerPage then exit do
          rs.movenext
       loop
          %>
</table>
8 回复
#2
yms1232010-08-15 20:49
数据库是SQL Server2005?
#3
a1900662010-08-15 21:05
回复 2楼 yms123
数据库是:Microsoft Office Access  *.mdb
#4
yms1232010-08-15 21:13
      totalPut=rs.recordcount
      totalPut=rs.recordcount
      if currentpage<1 then
          currentpage=1
      end if
      if (currentpage-1)*MaxPerPage>totalput then
       if (totalPut mod MaxPerPage)=0 then
         currentpage= totalPut \ MaxPerPage
       else
          currentpage= totalPut \ MaxPerPage + 1
       end if

      end if
       if currentPage=1 then
           showpage totalput,MaxPerPage,"index.asp"
            showContent
            showpage totalput,MaxPerPage,"index.asp"
       else
          if (currentPage-1)*MaxPerPage<totalPut then
            rs.move  (currentPage-1)*MaxPerPage
            dim bookmark
            bookmark=rs.bookmark
           showpage totalput,MaxPerPage,"index.asp"
            showContent
             showpage totalput,MaxPerPage,"index.asp"
        else
            currentPage=1
           showpage totalput,MaxPerPage,"index.asp"
           showContent
           showpage totalput,MaxPerPage,"index.asp"
          end if
       end if
ASP里没必要自己写分页算法的,这样反而更麻烦
#5
a1900662010-08-15 22:45
现在不是分页的问题。而是读二张表其中一个不会循环。字段:ok1可据ID循环,从1-2-3-4……

但表2 字段:ok2 只是循环了第一个ID的数据。如id 1 ok2 为“黄果树”,那么。从ID1---ID100都显示“黄果树”,其实id2 是“松树”,ID3 是:……
#6
wangjy5002010-08-16 22:02
那是当然了。!看你这一句。
<%do while not rs.eof%>
        <td><%=rs("id")%></td>
        <td><%=rs("ok1")%></td>
        <td><%=rs1("ok2")%></td>
    </tr>

<% i=i+1
          if i>=MaxPerPage then exit do
          rs.movenext
       loop
          %>
rs.movenext,,当然只能移动。rs的记录了。怎么能让他移动 rs1的记录呢。写法错误!!!
#7
zhanxinlin2010-08-17 00:28
回复 6楼 wangjy500
期待...
#8
funky2010-08-17 16:48
废话,能循环才怪. <%do while not rs.eof%> 只是在表users1中进行循环,你要读表二,你应该在这循环里,去where表2的数据.
#9
a1900662010-08-18 03:55
回复 8楼 funky
请问“去where表2的数据”是什么意思。能具体一点吗?
1