| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 640 人关注过本帖
标题:读二张表其中一个不会循环
只看楼主 加入收藏
a190066
Rank: 4
等 级:业余侠客
威 望:2
帖 子:175
专家分:204
注 册:2010-6-24
结帖率:79.07%
收藏
已结贴  问题点数:20 回复次数:8 
读二张表其中一个不会循环
读二张表其中一个不会循环。字段: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>
搜索更多相关主题的帖子: request where 
2010-08-15 20:30
yms123
Rank: 16Rank: 16Rank: 16Rank: 16
等 级:版主
威 望:209
帖 子:12488
专家分:19042
注 册:2004-7-17
收藏
得分:5 
数据库是SQL Server2005?
2010-08-15 20:49
a190066
Rank: 4
等 级:业余侠客
威 望:2
帖 子:175
专家分:204
注 册:2010-6-24
收藏
得分:0 
回复 2楼 yms123
数据库是:Microsoft Office Access  *.mdb
2010-08-15 21:05
yms123
Rank: 16Rank: 16Rank: 16Rank: 16
等 级:版主
威 望:209
帖 子:12488
专家分:19042
注 册:2004-7-17
收藏
得分:0 
      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里没必要自己写分页算法的,这样反而更麻烦
2010-08-15 21:13
a190066
Rank: 4
等 级:业余侠客
威 望:2
帖 子:175
专家分:204
注 册:2010-6-24
收藏
得分:0 
现在不是分页的问题。而是读二张表其中一个不会循环。字段:ok1可据ID循环,从1-2-3-4……

但表2 字段:ok2 只是循环了第一个ID的数据。如id 1 ok2 为“黄果树”,那么。从ID1---ID100都显示“黄果树”,其实id2 是“松树”,ID3 是:……
2010-08-15 22:45
wangjy500
Rank: 11Rank: 11Rank: 11Rank: 11
等 级:贵宾
威 望:13
帖 子:457
专家分:2569
注 册:2010-7-11
收藏
得分:5 
那是当然了。!看你这一句。
<%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的记录呢。写法错误!!!

QQ:63572063
2010-08-16 22:02
zhanxinlin
Rank: 3Rank: 3
等 级:论坛游侠
帖 子:96
专家分:156
注 册:2010-5-19
收藏
得分:5 
回复 6楼 wangjy500
期待...
2010-08-17 00:28
funky
Rank: 2
来 自:福建
等 级:论坛游民
帖 子:25
专家分:60
注 册:2010-8-10
收藏
得分:5 
废话,能循环才怪. <%do while not rs.eof%> 只是在表users1中进行循环,你要读表二,你应该在这循环里,去where表2的数据.

生命的真实为什么不能像水塘?懂得贮存,也不各自流淌。。
2010-08-17 16:48
a190066
Rank: 4
等 级:业余侠客
威 望:2
帖 子:175
专家分:204
注 册:2010-6-24
收藏
得分:0 
回复 8楼 funky
请问“去where表2的数据”是什么意思。能具体一点吗?
2010-08-18 03:55
快速回复:读二张表其中一个不会循环
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.013936 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved