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

asp分页代码和数据库问题

lzx_momo 发布于 2011-06-15 10:40, 770 次点击
最近我做个商业网站,是关于古钱币的网站,可是其中遇到了很多问题,我很难解决,因为动态的我不是很熟,所以那位高手帮我解决下,小弟不胜感激,咱遇到的问题就是分页代码的问题,代码如下
<table width="100%" border="0" cellspacing="0" cellpadding="0">
          <%
        dim everypagesize
        'response.Buffer=true
        everypagesize=3
        if request.QueryString("class")="" and session("classname")="" then
        sql="select * from product"
        else
          if request.QueryString("class")<>"" then
          session("classname")=request.QueryString("class")
          end if
          sql="select * from product where productclass='"&session("classname")&"'"
        end if
        
        rown=3
        rs.open sql,conn,3,1
if not rs.eof then
        if (rs.recordcount mod everypagesize) then
            pagenum=int(rs.recordcount/everypagesize)+1
        else
            pagenum=rs.recordcount/everypagesize
        end if
        pageno=request("pageno")
        if pageno="" then
            pageno=1
        end if
        rs.move (pageno-1)*everypagesize   
        for pageshow=1 to everypagesize
            if not rs.eof then
        %>
 


      <tr>
      <%for k=1 to rown%>
        <th width="100%" scope="col"><table width="100%" border="0" cellspacing="0" cellpadding="0">
          <tr>
            <th width="29%" scope="col"> </th>
            <th width="71%" scope="col"><img src=<%=rs("productimg")%> width="180" height="150"></th>
          </tr>
          <tr>
            <td> </td>
            <td> 商品名称:<%=rs("productname")%></td>
          </tr>
          <tr>
            <td> </td>
            <td> 商品类型:<%=rs("productclass")%></td>
          </tr>
        </table>         
        </th>
        <%next%>
      </tr>


            <%
            rs.movenext
             end if
        next
        'rs.close
        'set rs=nothing
        %>
    </table>
    <table width="100%" border="0" cellspacing="0" cellpadding="0">
        <tr>
          <td height="10" align="right"><div align="center"></div></td>
        </tr>
        <tr>
          <td height="5" align="right">共<%=rs.recordcount%>条商品 <div align="center"><a href="product.asp?pageno=1">首页</a>
              <% if pageno=1  then
               response.Write("上一页")
               else
             %>
              <a href="product.asp?pageno=<%=pageno-1%>">上一页</a>
              <%           
              end if
for i=1 to pagenum
response.Write("<a href=""product.asp?pageno="&i&"""> ["&i&"] </a>")
next
%>
              <%
            if pageno-pagenum=0 then
            response.Write("下一页")
            else
            %>
              <a href="product.asp?pageno=<%=pageno+1%>">下一页</a>
              <%
            end if
             %>
            <a href="product.asp?pageno=<%=pagenum%>">尾页</a></div></td>
        </tr>
      </table>

 <%end if%>   
这样做结果每行显示的都是同一个产品,且第一个连接就把数据库中的所有产品都拉出来了,好纠结啊。
7 回复
#2
dzt00012011-06-15 12:49

你用了两次循环,造成重复显示
for pageshow=1 to everypagesize

for k=1 to rown
#3
lzx_momo2011-06-15 18:00
回复 2楼 dzt0001
3Q,,原来是这样!~
#4
lzx_momo2011-06-15 21:30
回复 楼主 lzx_momo
不行啊,按照你的方法改了之后,网页就有错误打不开了!~
#5
dzt00012011-06-15 22:31
你怎么改的?是什么错误?
#6
lzx_momo2011-06-16 09:58
回复 5楼 dzt0001
你有QQ吗,我把源文件传给你看看就知道了,但这可能要麻烦你了!~
#7
yms1232011-06-16 11:29
什么数据库?ASP有自带的分页方法,为什么要自己写分页算分呢?
#8
lzx_momo2011-06-16 23:07
回复 7楼 yms123
就是产品数据库啊,在数据库中添加产品那样的,还有你说得asp自带的分页是啥东东,俺学ASP不久,

[ 本帖最后由 lzx_momo 于 2011-6-17 10:18 编辑 ]
1