asp分页显示代码问题
我的代码,不能打开“下一页”和“最后一页”,怎么也找不出来错在哪儿?求助各位。<%Dimmykeymykey=request.form("keywords")Setcon...
我的代码,不能打开“下一页”和“最后一页”,怎么也找不出来错在哪儿?求助各位。
<%
Dim mykey
mykey=request.form("keywords")
Set conn=Server.CreateObject("ADODB.Connection")
Conn.ConnectionString="Provider=Microsoft.Jet.OLEDB.4.0;Data Source="& Server.MapPath("LI!DATA/rzsf#lijianhua= =%0633%.mdb")
Conn.Open
Set rs=Server.CreateObject("ADODB.Recordset")
Set rs.ActiveConnection=Conn
rs.CursorType=3
rs.Open"Select * From lijianhua0633 Where gjc Like '%"&mykey&"%' Order by dw"
Response.Write("<br>本次共查询到“ <font color=red>"&mykey&"</font> ”<font color=red> "& CStr(rs.RecordCount)& "</font> 条。<br>")
rs.PageSize = 20
'读取参数
page = CLng(Request.QueryString("page"))
'处理无效页码
If page < 1 Then
page = 1
End If
If page > rs.PageCount Then
page = rs.PageCount
End If
'设置当前页
rs.AbsolutePage = page
%>
<hr style="width: 80%; height: 1px" class="style1"/><br/>当前页码:<%=page%>/<%=rs.PageCount%>
<table style="width: 990px" cellspacing="1" align="center">
<tr>
<td style="width: 650px">
<table cellspacing="0" cellpadding="0" class="style3" style="width: 623px">
<tr> <td style="width:50px; height: 25px;" class="style6"> 序号</td>
<td style="width:600px; height: 25px;" class="style4">
<span class="style5">单位名称</span></td></tr>
<%
For i = 1 To rs.PageSize
varNo = (page - 1) * rs.PageSize + i
Response.Write("<tr> <td height=35px> " & CStr(i+1) & "</td> <td height=35px> <a href=searchtel02.asp?ID="& rs.Fields(1).Value &">"& rs.Fields(1).Value &"</a></td></tr>")
rs.MoveNext
'如果已经到达记录集结尾,则退出循环
If rs.EOF Then Exit For
Next
Response.Write("<BR>")
%>
</td>
</tr>
<%
%>
<tr>
<td style="width: 650px" class="style7">
<%
'设置“第一页”链接
If page = 1 Then
Response.Write("第一页 ")
Else
Response.Write(" <a href=searchtel.asp?page=1>第一页</a> ")
End If
'设置“上一页”链接
If page = 1 Then
Response.Write(" 上一页 ")
Else
Response.Write(" <a href=searchtel.asp?page=" & page-1 & ">上一页</a> ")
End If
'设置“下一页”链接
If page = rs.PageCount Then
Response.Write(" 下一页 ")
Else
Response.Write(" <a href=searchtel.asp?page=" & page+1 & ">下一页</a> ")
End If
'设置“最后一页”链接
If page = rs.PageCount Then
Response.Write(" 最后一页 ")
Else
Response.Write(" <a href=searchtel.asp?page=" & rs.PageCount &">最后一页</a> ")
End If
%>
</td>
</tr>
</table>
<% Conn.Close
Set Conn=nothing
%>
当前页面为:/searchtel.asp
第二位(匿名)先生:
您好,还是存在问题,不论点击下一页,还是最后一页,打开的却是整个数据库信息,而非要查询的内容,请您再帮我修改一下,就要成功了。先谢了 。
会不会与服务器端有关?
binghe130:出了错误:
Microsoft VBScript 编译器错误 错误 '800a0408'
无效字符
/shiyan/searchtel.asp,行76
do while (not rs.eof) and (rs_NO < maxperpage)
-------------------------^
能否给我写一个完整的代码?麻烦您了 展开
<%
Dim mykey
mykey=request.form("keywords")
Set conn=Server.CreateObject("ADODB.Connection")
Conn.ConnectionString="Provider=Microsoft.Jet.OLEDB.4.0;Data Source="& Server.MapPath("LI!DATA/rzsf#lijianhua= =%0633%.mdb")
Conn.Open
Set rs=Server.CreateObject("ADODB.Recordset")
Set rs.ActiveConnection=Conn
rs.CursorType=3
rs.Open"Select * From lijianhua0633 Where gjc Like '%"&mykey&"%' Order by dw"
Response.Write("<br>本次共查询到“ <font color=red>"&mykey&"</font> ”<font color=red> "& CStr(rs.RecordCount)& "</font> 条。<br>")
rs.PageSize = 20
'读取参数
page = CLng(Request.QueryString("page"))
'处理无效页码
If page < 1 Then
page = 1
End If
If page > rs.PageCount Then
page = rs.PageCount
End If
'设置当前页
rs.AbsolutePage = page
%>
<hr style="width: 80%; height: 1px" class="style1"/><br/>当前页码:<%=page%>/<%=rs.PageCount%>
<table style="width: 990px" cellspacing="1" align="center">
<tr>
<td style="width: 650px">
<table cellspacing="0" cellpadding="0" class="style3" style="width: 623px">
<tr> <td style="width:50px; height: 25px;" class="style6"> 序号</td>
<td style="width:600px; height: 25px;" class="style4">
<span class="style5">单位名称</span></td></tr>
<%
For i = 1 To rs.PageSize
varNo = (page - 1) * rs.PageSize + i
Response.Write("<tr> <td height=35px> " & CStr(i+1) & "</td> <td height=35px> <a href=searchtel02.asp?ID="& rs.Fields(1).Value &">"& rs.Fields(1).Value &"</a></td></tr>")
rs.MoveNext
'如果已经到达记录集结尾,则退出循环
If rs.EOF Then Exit For
Next
Response.Write("<BR>")
%>
</td>
</tr>
<%
%>
<tr>
<td style="width: 650px" class="style7">
<%
'设置“第一页”链接
If page = 1 Then
Response.Write("第一页 ")
Else
Response.Write(" <a href=searchtel.asp?page=1>第一页</a> ")
End If
'设置“上一页”链接
If page = 1 Then
Response.Write(" 上一页 ")
Else
Response.Write(" <a href=searchtel.asp?page=" & page-1 & ">上一页</a> ")
End If
'设置“下一页”链接
If page = rs.PageCount Then
Response.Write(" 下一页 ")
Else
Response.Write(" <a href=searchtel.asp?page=" & page+1 & ">下一页</a> ")
End If
'设置“最后一页”链接
If page = rs.PageCount Then
Response.Write(" 最后一页 ")
Else
Response.Write(" <a href=searchtel.asp?page=" & rs.PageCount &">最后一页</a> ")
End If
%>
</td>
</tr>
</table>
<% Conn.Close
Set Conn=nothing
%>
当前页面为:/searchtel.asp
第二位(匿名)先生:
您好,还是存在问题,不论点击下一页,还是最后一页,打开的却是整个数据库信息,而非要查询的内容,请您再帮我修改一下,就要成功了。先谢了 。
会不会与服务器端有关?
binghe130:出了错误:
Microsoft VBScript 编译器错误 错误 '800a0408'
无效字符
/shiyan/searchtel.asp,行76
do while (not rs.eof) and (rs_NO < maxperpage)
-------------------------^
能否给我写一个完整的代码?麻烦您了 展开
4个回答
2009-08-25
展开全部
Set rs=Server.CreateObject("ADODB.Recordset")
Set rs.ActiveConnection=Conn
rs.CursorType=3
rs.Open"Select * From lijianhua0633 Where gjc Like '%"&mykey&"%' Order by dw"
Response.Write("<br>本次共查询到“ <font color=red>"&mykey&"</font> ”<font color=red> "& CStr(rs.RecordCount)& "</font> 条。<br>")
'=====================删除原来的,把这段代码复制上===================
rs.pagesize=20
page=clng(request("page"))
if page="" or page<1 then page=1
if not page=1 then rs.move (page-1)*rs.pagesize
'===================================================================
<%
if page=1 then
response.write"第一页"
end if
if page<>1 then
response.write"<a href=searchtel.asp?page=1&mykey="&mykey&">第一页</a>"
response.write"<a href=searchtel.asp?page="&(page-1)&"&mykey="&mykey&">上一页</a>"
end if
if page<>rs.pagecount then
response.write"<a href=searchtel.asp?page="&(page+1)&"&mykey="&mykey&">下一页</a>"
response.write"<a href=searchtel.asp?page="&rs.pagecount&"&mykey="&mykey&">最后一页</a>"
end if
if page=rs.pagecount then
response.write"最后一页"
end if
%>
Set rs.ActiveConnection=Conn
rs.CursorType=3
rs.Open"Select * From lijianhua0633 Where gjc Like '%"&mykey&"%' Order by dw"
Response.Write("<br>本次共查询到“ <font color=red>"&mykey&"</font> ”<font color=red> "& CStr(rs.RecordCount)& "</font> 条。<br>")
'=====================删除原来的,把这段代码复制上===================
rs.pagesize=20
page=clng(request("page"))
if page="" or page<1 then page=1
if not page=1 then rs.move (page-1)*rs.pagesize
'===================================================================
<%
if page=1 then
response.write"第一页"
end if
if page<>1 then
response.write"<a href=searchtel.asp?page=1&mykey="&mykey&">第一页</a>"
response.write"<a href=searchtel.asp?page="&(page-1)&"&mykey="&mykey&">上一页</a>"
end if
if page<>rs.pagecount then
response.write"<a href=searchtel.asp?page="&(page+1)&"&mykey="&mykey&">下一页</a>"
response.write"<a href=searchtel.asp?page="&rs.pagecount&"&mykey="&mykey&">最后一页</a>"
end if
if page=rs.pagecount then
response.write"最后一页"
end if
%>
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
分页问题已经有人帮你解决了,现在要解决的是显示记录的部分
<%
'maxperpage 为每页显示记录条数,自己定义
maxperpage = 10
N=(page - 1) * maxperpage + 1
rs_NO=0
rs.move n-1 '第一条记录编号是0 所以 这里要用N-1 而不能用N
do while (not rs.eof) and (rs_NO < maxperpage)
Response.Write("<tr> <td height=35px> " & CStr(i+1) & "</td> <td height=35px> <a href=searchtel02.asp?ID="& rs.Fields(1).Value &">"& rs.Fields(1).Value &"</a></td></tr>")
rs.MoveNext
rs_NO=rs_NO+1
LOOP
'=======================================================
'思路:将整个表的记录读取到记录集 RS , 显示时,根据提交的页码 计算出应该从第几条记录开始显示,显示指定的记录数同时又能判断是否到记录尾用 do while (not rs.eof) and (rs_NO < maxperpage) 就能实现。
%>
看到你提示的错误,检查“(”和“)”是否是半角状态下输入的。我把我的回复重新修改了一下,你再试试
<%
'maxperpage 为每页显示记录条数,自己定义
maxperpage = 10
N=(page - 1) * maxperpage + 1
rs_NO=0
rs.move n-1 '第一条记录编号是0 所以 这里要用N-1 而不能用N
do while (not rs.eof) and (rs_NO < maxperpage)
Response.Write("<tr> <td height=35px> " & CStr(i+1) & "</td> <td height=35px> <a href=searchtel02.asp?ID="& rs.Fields(1).Value &">"& rs.Fields(1).Value &"</a></td></tr>")
rs.MoveNext
rs_NO=rs_NO+1
LOOP
'=======================================================
'思路:将整个表的记录读取到记录集 RS , 显示时,根据提交的页码 计算出应该从第几条记录开始显示,显示指定的记录数同时又能判断是否到记录尾用 do while (not rs.eof) and (rs_NO < maxperpage) 就能实现。
%>
看到你提示的错误,检查“(”和“)”是否是半角状态下输入的。我把我的回复重新修改了一下,你再试试
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
ASP+ACCESS的
<%
Set conn=Server.CreateObject("Adodb.Connection")
connstr="provider=Microsoft.JET.OLEDB.4.0;Data Source="&Server.MapPath("data.mdb")
conn.open connstr
Set rs=Server.CreateObject("Adodb.Recordset")
sql="Select * from info"
rs.open sql,conn,1,1
%>
<%
rs.pagesize=5 '每页记录条数
curpage=Request.QueryString("curpage") '将URL参数curpage传给curpage变量
if curpage="" then curpage=1
rs.absolutepage=curpage '将本页设为curpage设置的页数
%>
<%
for i= 1 to rs.pagesize
if rs.eof then
exit for
end if
%>
<%=rs("record_info")%><br>
<%
rs.movenext
next
%>
<br>
<div>当前第<%=curpage%>页,共有<%=rs.pagecount%>页,共有:<%=rs.recordcount%>条记录</div>
<%if curpage=1 then%>
首页
<%else%>
<a href="?curpage=1">首页</a>
<%end if%>
<%if curpage=1 then%>
上一页
<%else%>
<a href="?curpage=<%=curpage-1%>">上一页</a>
<%end if%>
<%if rs.pagecount<curpage+1 then%>
下一页
<%else%>
<a href="?curpage=<%=curpage+1%>">下一页</a>
<%end if%>
<%if rs.pagecount<curpage+1 then%>
尾页
<%else%>
<a href="?curpage=<%=rs.pagecount%>">尾页</a>
<%end if%>
-------------------------------------------------------------
ASP+mysql 的我已经试过了,你改动一下就可以用
<!--#include file="conn.asp"-->
<%
dim totalPut
dim CurrentPage
dim TotalPages
dim i,j
const MaxPerPage = 10 '定义每一页的记录条数
'获取当前页面
if not isempty(request("page")) then
currentPage = cint(request("page"))
else
currentPage = 1
end if
'获取记录总数和总页数
Set Rs = Conn.execute("select count(*) from unionuser ")
totalPut = cint(rs(0))
if totalPut mod maxperpage = 0 then '假如有20条记录,TotalPages = 2 页,假如有25条记录,TotalPages = 2 + 1
TotalPages = totalPut \ maxperpage
else
TotalPages = totalPut \ maxperpage + 1
end if
Set rs= Server.CreateObject ("ADODB.RecordSet")
rs.open "select * from unionuser order by id desc LIMIT "&(currentPage-1)*MaxPerPage&","&MaxPerPage,conn,1,3
'--------------------------------------------------------------------------------------调用内容和分页函数
call showcontent
call showpage
'--------------------------------------------------------------------------------------内容
sub showcontent
response.write "<table width=""100%"" border=""1"" align=""center"">"
response.write " <tr>"
response.write " <td>id</td>"
response.write " <td>userid</td>"
response.write " <td>userpassword</td>"
response.write " <td>nickname</td>"
response.write " <td>gender</td>"
response.write " </tr>"
dim i
i=0
do while not rs.eof
'-----------------------------------------------------------------------------
'显示内容
'-----------------------------------------------------------------------------
id = rs("id")
userid = rs("userid")
userpassword = rs("userpassword")
nickname = rs("nickname")
gender = rs("gender")
%>
<tr>
<td><%=id%></td>
<td><%=userid%></td>
<td><%=userpassword%></td>
<td><%=nickname%></td>
<td><%=gender%></td>
</tr><%
i=i+1
if i >= MaxPerPage then exit do
rs.movenext
loop
%></td>
</tr>
</table><%
end sub
'------------------------------------------------------------------------------------------分页
sub showpage
response.Write("<table><TR><TD>")
response.write "<form name=myform method=get action="""">"
if CurrentPage<2 then
' 显示页数链接的条件
response.write "<font color='#999999'>首页 上一页</font> "
else
response.write "<a href=?page=1>首页</a> "
response.write "<a href=?page="&CurrentPage-1&">上一页</a> "
end if
if TotalPages-currentpage<1 then
response.write "<font color='#999999'>下一页 尾页</font> "
else
response.write "<a href=?page="&(CurrentPage+1)
response.write ">下一页</a> <a href=?page="&TotalPages&">尾页</a> "
end if
response.write "<font color='#000000'>页次</font> <font color=red>"&CurrentPage&"</font><font color='#000000'>/"&TotalPages&"页</font> "
response.write "<font color='#000000'>共<b>"&totalPut&"</b>个 <b>"&maxperpage&"</b>个/页</font>"
response.write " <font color='#000000'>转到:</span>"
response.Write("<select name='page' onchange='{this.document.myform.submit();return true;}'>")
for i=1 to TotalPages
if i=currentPage then
response.Write("<option selected value="&i&">")
else
response.Write("<option value="&i&">")
end if
response.Write("第"&i&"页</option>")
next
response.Write("</td></tr></table>")
response.Write("</select></form>")
end sub
%>
<%
Set conn=Server.CreateObject("Adodb.Connection")
connstr="provider=Microsoft.JET.OLEDB.4.0;Data Source="&Server.MapPath("data.mdb")
conn.open connstr
Set rs=Server.CreateObject("Adodb.Recordset")
sql="Select * from info"
rs.open sql,conn,1,1
%>
<%
rs.pagesize=5 '每页记录条数
curpage=Request.QueryString("curpage") '将URL参数curpage传给curpage变量
if curpage="" then curpage=1
rs.absolutepage=curpage '将本页设为curpage设置的页数
%>
<%
for i= 1 to rs.pagesize
if rs.eof then
exit for
end if
%>
<%=rs("record_info")%><br>
<%
rs.movenext
next
%>
<br>
<div>当前第<%=curpage%>页,共有<%=rs.pagecount%>页,共有:<%=rs.recordcount%>条记录</div>
<%if curpage=1 then%>
首页
<%else%>
<a href="?curpage=1">首页</a>
<%end if%>
<%if curpage=1 then%>
上一页
<%else%>
<a href="?curpage=<%=curpage-1%>">上一页</a>
<%end if%>
<%if rs.pagecount<curpage+1 then%>
下一页
<%else%>
<a href="?curpage=<%=curpage+1%>">下一页</a>
<%end if%>
<%if rs.pagecount<curpage+1 then%>
尾页
<%else%>
<a href="?curpage=<%=rs.pagecount%>">尾页</a>
<%end if%>
-------------------------------------------------------------
ASP+mysql 的我已经试过了,你改动一下就可以用
<!--#include file="conn.asp"-->
<%
dim totalPut
dim CurrentPage
dim TotalPages
dim i,j
const MaxPerPage = 10 '定义每一页的记录条数
'获取当前页面
if not isempty(request("page")) then
currentPage = cint(request("page"))
else
currentPage = 1
end if
'获取记录总数和总页数
Set Rs = Conn.execute("select count(*) from unionuser ")
totalPut = cint(rs(0))
if totalPut mod maxperpage = 0 then '假如有20条记录,TotalPages = 2 页,假如有25条记录,TotalPages = 2 + 1
TotalPages = totalPut \ maxperpage
else
TotalPages = totalPut \ maxperpage + 1
end if
Set rs= Server.CreateObject ("ADODB.RecordSet")
rs.open "select * from unionuser order by id desc LIMIT "&(currentPage-1)*MaxPerPage&","&MaxPerPage,conn,1,3
'--------------------------------------------------------------------------------------调用内容和分页函数
call showcontent
call showpage
'--------------------------------------------------------------------------------------内容
sub showcontent
response.write "<table width=""100%"" border=""1"" align=""center"">"
response.write " <tr>"
response.write " <td>id</td>"
response.write " <td>userid</td>"
response.write " <td>userpassword</td>"
response.write " <td>nickname</td>"
response.write " <td>gender</td>"
response.write " </tr>"
dim i
i=0
do while not rs.eof
'-----------------------------------------------------------------------------
'显示内容
'-----------------------------------------------------------------------------
id = rs("id")
userid = rs("userid")
userpassword = rs("userpassword")
nickname = rs("nickname")
gender = rs("gender")
%>
<tr>
<td><%=id%></td>
<td><%=userid%></td>
<td><%=userpassword%></td>
<td><%=nickname%></td>
<td><%=gender%></td>
</tr><%
i=i+1
if i >= MaxPerPage then exit do
rs.movenext
loop
%></td>
</tr>
</table><%
end sub
'------------------------------------------------------------------------------------------分页
sub showpage
response.Write("<table><TR><TD>")
response.write "<form name=myform method=get action="""">"
if CurrentPage<2 then
' 显示页数链接的条件
response.write "<font color='#999999'>首页 上一页</font> "
else
response.write "<a href=?page=1>首页</a> "
response.write "<a href=?page="&CurrentPage-1&">上一页</a> "
end if
if TotalPages-currentpage<1 then
response.write "<font color='#999999'>下一页 尾页</font> "
else
response.write "<a href=?page="&(CurrentPage+1)
response.write ">下一页</a> <a href=?page="&TotalPages&">尾页</a> "
end if
response.write "<font color='#000000'>页次</font> <font color=red>"&CurrentPage&"</font><font color='#000000'>/"&TotalPages&"页</font> "
response.write "<font color='#000000'>共<b>"&totalPut&"</b>个 <b>"&maxperpage&"</b>个/页</font>"
response.write " <font color='#000000'>转到:</span>"
response.Write("<select name='page' onchange='{this.document.myform.submit();return true;}'>")
for i=1 to TotalPages
if i=currentPage then
response.Write("<option selected value="&i&">")
else
response.Write("<option value="&i&">")
end if
response.Write("第"&i&"页</option>")
next
response.Write("</td></tr></table>")
response.Write("</select></form>")
end sub
%>
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询