主题:  求助:分页问题

mantilla

职务:普通成员
等级:1
金币:0.0
发贴:30
#12006/2/4 9:26:33
<table border="0" cellpadding="0" cellspacing="0" style="border-collapse: collapse" id="AutoNumber3" height="0" width="100%">
<tr>
<td>
<%'开始分页
                Const MaxPerPage=5
                dim totalPut
                dim CurrentPage
                dim TotalPages
                dim j
                dim sql
                if Not isempty(request("page") then
                currentPage=Cint(request("page")
                else
                currentPage=1
                end if
         if zclassid="" then
         set rs=server.CreateObject("adodb.recordset"
         rs.open "select top 10 qch,jj,rq,bookid,bookname,bookzz,bookchuban,shichangjia,huiyuanjia,dazhe,bookdate,bookpic from shop_books order by adddate desc",conn,1,1
         else
         set rs=server.CreateObject("adodb.recordset"
         rs.open "select bookid,bookname,bookzz,bookchuban,shichangjia,huiyuanjia,dazhe,bookdate,bookpic from shop_books where zclassid="&zclassid&" order by adddate desc",conn,1,1
         end if
        
                if err.number<>0 then
                response.write "数据库中无数据"
                end if
                
                if rs.eof And rs.bof then
                Response.Write "<p align='center' class='contents'> 对不起,此分类暂时还没有商品!</p>"
                else
                     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
            showContent
            showpage totalput,MaxPerPage,"class.asp"
                else
                if (currentPage-1)*MaxPerPage<totalPut then
                rs.move (currentPage-1)*MaxPerPage
                dim bookmark
                bookmark=rs.bookmark
                showContent
                showpage totalput,MaxPerPage,"class.asp"
                else
                     currentPage=1
                    showContent
                    showpage totalput,MaxPerPage,"class.asp"
                     end if
                     end if
                                 end if

                sub showContent
            dim i
                 i=0

            %>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<%if zclassid="" then
             response.write "<tr><td><img src=images/newbooks.gif width=520 height=31 alt=新到商品TOP20></td></tr>"
         else
             dim rs2,zname,nname,aname,tmpid
             set rs2=server.CreateObject("adodb.recordset"
            rs2.open "select * from shop_zclass where zclassid="&zclassid,conn,1,1
            tmpid=rs2("nclassid"
            zname=rs2("zClass"
            rs2.close
            rs2.open "select * from shop_nclass where nclassid="&tmpid,conn,1,1
            tmpid=rs2("anclassid"
            nname=rs2("nClass"
            rs2.close
            rs2.open "select * from shop_anclass where anclassid="&tmpid,conn,1,1
            aname=rs2("anClass"
            rs2.close
            set rs2=nothing
             response.write "<tr><td width=520 height=31><b>"&aname&"-"&nname&"-"&zname&"</b></td></tr>"
         end if%>
<tr>
<td>
<%
            do while not rs.eof%>

<div align="center">
<table width="100%" border="0" cellpadding="3" cellspacing="0">
<tr>
<td height="1" colspan="2" valign="top" bgcolor="#cccccc"></td>
</tr>
<tr>

<td width="18%" valign="top">
<div align="center">
<table width="65" height="94" border="0" cellpadding="0" cellspacing="0">
<tr>
<td bgcolor="#FFFFFF">
<%
response.Write "<a href=book.asp?id="&rs("bookid"&">"
if trim(rs("bookpic")<>"" then
response.Write "<img src="&trim(rs("bookpic")&" width=120 height=120 border=0 ></a>"
else
response.Write "<img src=images/emptybook.gif width=65 height=96 border=0></a>"
end if%><img src="../images/spacer.gif" width="12" height="1"></td>
</tr>
</table>
</div>
</td>
<td width="82%">
<table width="100%" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td colspan="3" height="10">
                                                        <table border="0" width="100%" cellspacing="0" cellpadding="0">
                                                            <tr>
                                                                <td width="60%" height="30"><strong><font class="bookn"><%=trim(rs("bookname")%></font></strong></td>
                                                                <td width="40%"><img border="0" src="IMAGES/index_ic01.gif" width="73" height="17"></td>
                                                            </tr>
                                                        </table>
                                                        </td>
</tr>
<tr>
<td colspan="3"><font color="#999966"><%=trim(rs("bookzz")%></font></td>
</tr>
<tr>
<td colspan="3" height="30"><a href="book.asp?id=<%=rs("bookid"%>"><img border="0" src="IMAGES/btn_moreinfo.gif" width="64" height="17"></a></td>
</tr>
<tr>
<td background="images/line_broke01.gif" colspan="2"><img height="5" alt="" src="images/line_broke01.gif" width="16" border="0"></td>
                 </tr>
                 <tr><td height="5"></td></tr>
<tr>
<td colspan="3"> <%=trim(rs("bookdate")%></td>
</tr>
<tr>
<td width="37%"><%=formatnumber(rs("shichangjia",2)&"元"%>(会员价<%=formatnumber(rs("huiyuanjia",2)&"元"%></td>
<td width="63%" align="right">
                                                        <%response.write "<a href=# onClick=""javascript:window.open('shopping.asp?id="&rs("bookid"&"','','width=632,height=388,toolbar=no, status=no, menubar=no, resizable=yes, scrollbars=yes');return false;""><img src=images/gm.gif border=0></a>"%></td>
</tr>
<tr><td height="10" colspan="2"></td></tr>
</table>
</td>
</tr>
<tr>
<td colspan="2" valign="top" height="1"></td>
</tr>
</table>
</div>
<%
            i=i+1
            if i>=MaxPerPage then Exit Do
            rs.movenext
            loop
            rs.close
            set rs=nothing
            %>
</td>
</tr>
<tr><td height="1" bgcolor="#cccccc"></td></tr>
</table>
<%
                End Sub

                Function showpage(totalnumber,maxperpage,filename)
                Dim n,ii
                
                If totalnumber Mod maxperpage=0 Then
                    n= totalnumber \ maxperpage
                Else
                    n= totalnumber \ maxperpage+1
                End If
                
                Response.Write "<form method=Post action="&filename&"?zid="&zclassid&">"
                If CurrentPage<2 Then
                    Response.Write "<font>首页 | 上一页 | </font> "
                Else
                    Response.Write "<a href="&filename&"?page=1&zid="&zclassid&">首页</a> | "
                    Response.Write "<a href="&filename&"?page="&CurrentPage-1&"&zid="&zclassid&">上一页</a> | "
                End If
                
                If n-currentpage<1 Then
                    Response.Write "<font>下一页 | 尾页</font>"
                Else
                    Response.Write "<a href="&filename&"?page="&(CurrentPage+1)&"&zid="&zclassid&">"
                    Response.Write "下一页</a> <a href="&filename&"?page="&n&"&zid="&zclassid&">尾页</a>"
                End If
                    Response.Write "<font> 页次:</font><font>"&CurrentPage&"</font><font>/"&n&"页</font> "    
                    Response.Write "<font> 共有"&totalnumber&"种商品 "
                    Response.Write "<font>转到:</font><input type='text' name='page' size=2 maxlength=10 class=smallInput value="&currentpage&">"
                    Response.Write "&nbsp;<input type='submit' value='GO' name='cndok'></form>"

                End Function
            %>
</td>
</tr>
</table>


请问怎么样才能使页码按 1 2 3 4 页这样来分,而不是上一页下一页



三仙半

职务:普通成员
等级:1
金币:0.0
发贴:241
#22006/2/4 13:26:55
你试一下下面这段话:
for I = 1 to rs.pageCount
Response.Write "<a href="&filename&"?page="& I &"&zid="&zclassid&">"
Response.Write I &"</a>&nbsp;&nbsp;&nbsp;"
next
这段话放在原来写“上一页”“下一页”那个地方。
另外,使用代码时勾选“禁止转换表情图标”,否则代码太难读!!!


闭起眼睛看人生

mantilla

职务:普通成员
等级:1
金币:0.0
发贴:30
#32006/2/4 22:14:14
我用 for i=1 to n

解决了,谢谢楼上。

现在的问题是,如何让产品横过来排,不知道怎么解决



mantilla

职务:普通成员
等级:1
金币:0.0
发贴:30
#42006/2/5 9:39:52
还有继续分页问题,就是

如何使 i=当前页(currentpage的时候,i没有链接

就是怎么把 if i=currentpage then
response.write "<"&i&">"

加进去



三仙半

职务:普通成员
等级:1
金币:0.0
发贴:241
#52006/2/8 17:06:04
把原来那段话换成下面这段:
for I = 1 to rs.pageCount
if i=currentPage then
Response.Write I &"nbsp;&nbsp;&nbsp;"
else
Response.Write "<a href="&filename&"?page="& I &"&zid="&zclassid&">"
Response.Write I &"</a>&nbsp;&nbsp;&nbsp;"
end if
next
原理就是判断如果是当前页就不写链接;否则写。


闭起眼睛看人生

三仙半

职务:普通成员
等级:1
金币:0.0
发贴:241
#62006/2/8 17:22:46
关于横过来,你的代码太多,我没办法改,我写个简单的,你参考。
<%
sub showPage(rs,page_Size,pageNum)
if pageNum > rs.pageCount then pageNum = rs.pageCount
rs.absolutePage = pageNum
response.write "<table><tr>"
for i =1 to page_Size
response.write "<td><table>"
for j = 1 to rs.fields.count
response.write "<tr><td>"
response.write rs.field(j)
response.write "</td></tr>"
next
response.write "</table></td>"
rs.moveNext
if rs.eof then exit for
next
response.write "</tr></table>"
end sub
%>
这是只有一个单行的情况,如果需要M*N的表格,可以将page_Size替换为pageWidth和pageHeight,然后将原来的"I"循环改成双层嵌套的就可以了。


闭起眼睛看人生

飞呀飞~~

职务:普通成员
等级:1
金币:0.2
发贴:164
#72006/2/13 1:04:40
zys59在上个帖子中说
引用:
你试一下下面这段话:
for I = 1 to rs.pageCount
Response.Write "<a href="&filename&"?page="& I &"&zid="&zclassid&">"
Response.Write I &"</a>&nbsp;&nbsp;&nbsp;"
next
这段话放在原来写“上一页”“下一页”那个地方。
另外,使用代码时勾选“禁止转换表情图标”,否则代码太难读!!!




飞呀飞~~

职务:普通成员
等级:1
金币:0.2
发贴:164
#82006/2/13 1:05:12
bettie19821031在上个帖子中说
引用:
zys59在上个帖子中说
引用:
你试一下下面这段话:
for I = 1 to rs.pageCount
Response.Write "<a href="&filename&"?page="& I &"&zid="&zclassid&">"
Response.Write I &"</a>&nbsp;&nbsp;&nbsp;"
next
这段话放在原来写“上一页”“下一页”那个地方。
另外,使用代码时勾选“禁止转换表情图标”,否则代码太难读!!!




规范化



三仙半

职务:普通成员
等级:1
金币:0.0
发贴:241
#92006/2/14 20:49:00
bettie19821031:
哥哥,我笨,总感觉自学很难,所以不希望别人象我一样遭罪,所以冒昧回答,不要见笑。


闭起眼睛看人生