奇怪的搜索结果分页问题
能准确显示页数和条数,但就不能分页,依然所有搜索结果都是显示在一页。
代码如下:
<!--#include file="utf-8.asp"-->
<!--#include file="conn.asp" -->
<!--#include file="config.asp" -->
<!--#include file="page.asp" -->
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title><%=request("key")%> - 先泽电器开关搜索“<%=request("key")%>”</title>
<meta name="description" content="您现正搜索的是:<%=request("key")%>;<%=config("description")%>" />
<meta name="keywords" content="<%=request("key")%>,<%=config("keywords")%>" />
<link href="images/style.css" type="text/css" rel="stylesheet" />
</head>
<body bgcolor="<%=config("bg")%>">
<!--#include file="header.asp" -->
<div align="center"><img src="/images/logo.jpg" width="100" height="80" alt="奇怪的搜索结果分页有关问题"title")%>" title="<%=config("title")%>" /></div>
<tr>
<td height="20">
<div style="border-bottom:#005AB5 15px solid;"></div></td>
</tr>
<!--#include file="search_so.asp" -->
<%
t=Trim(Request.Form("t"))
key=Trim(Request.Form("key"))
if t="" or key="" then
Response.Write("<script>alert('请输入关键词!');history.back();</script>")
Response.End()
end if
if t=1 then
sql="select * from [shop] where 1=0"
else
sql="select * from [news] where 1=0"
end if
keyArr=split(key," ")
for i=0 to ubound(keyArr)
sql=sql&" or title like '%"&keyArr(i)&"%'"
next
set rs=conn.execute(sql)
if t=1 then
%>
<table width="917" border="0" align="center" cellpadding="2" cellspacing="0" bgcolor="#FFFFFF">
<tr>
<td colspan="2" valign="top"><table width="100%" border="0" cellpadding="1" cellspacing="1" bgcolor="#F0F0F0">
<tr>
<td bgcolor="#EBEBEB"><table width="98%" border="0" cellpadding="10" cellspacing="0">
<tr>
<td> <b>关于先泽电器开关“<font color="#FF0000"><%=key%></font>”的搜索结果:</b></td>
</tr>
</table></td>
</tr>
<tr>
<td valign="top" bgcolor="#FFFFFF">
<tr>
<td><table width="155" border="0" cellpadding="0" cellspacing="0">
<tr>
<%
dim i
i=1
do while not rs.eof
%>
<td><table width="100%" border="0" cellpadding="5" cellspacing="1">
<tr>
<td><div align="center"><a href="showshop.asp?id=<%=rs("id")%>" class="img"><img src="<%=rs("img")%>" width="128" height="100" /></a></div></td>
</tr>
<tr>
<td><div align="center"><a href="showshop.asp?id=<%=rs("id")%>"><%=replace(rs("title"),Request.Form("key"),"<font color=red>"&Request.Form("key")&"</font>")%></a></div></td>
</tr>
</table></td>
<%
if i mod 6=0 then
response.Write "<tr>"
end if
i=i+1
rs.movenext
loop
%>
</tr>
</table></td>
</tr>
</table>
<%else%>
<table width="917" border="0" align="center" cellpadding="2" cellspacing="0" bgcolor="#FFFFFF">
<tr>
<td colspan="2" valign="top"><table width="100%" border="0" cellpadding="1" cellspacing="1" bgcolor="#F0F0F0">
<tr>
<td bgcolor="#EBEBEB"><table width="98%" border="0" cellpadding="10" cellspacing="0">
<tr>
<td> <b>关于先泽电器开关“<font color="#FF0000"><%=key%></font>”的搜索结果:</b></td>
</tr>
</table></td>
</tr>
<tr>
<td>
<%
if rs.eof then
response.write ("没有搜索到相关内容")
else
%>
<div class="box14">
<ul>
<% do while not rs.eof %>
<%
title=rs("title")
for i=0 to ubound(keyArr)
keyArr=split(Request.Form("key")," ")
title=replace(title,keyArr(i),"<font color=red>"&keyArr(i)&"</font>")
next
%>
<li> <a href="shownews.asp?id=<%=rs("id")%>"><%=title%></a><img src="/images/search_top.gif" alt="奇怪的搜索结果分页有关问题"title")%>" /> <%=rs("data")%></li>
<%rs.movenext
loop %>
</ul>
</div>
</td>
</tr>
</table></td>
</tr>
</table>
<%
end if
end if
%></td>
</tr>
<%
set rs=server.createobject("adodb.recordset")
rs.open sql,conn,1,1
rs.PageSize=10 '每页记录条数
iCount=rs.RecordCount '记录总数
iPageSize=rs.PageSize
maxpage=rs.PageCount
page=request("page")
if Not IsNumeric(page) or page="" then
page=1
else
page=cint(page)
end if
if page<1 then
page=1
elseif page>maxpage then
page=maxpage
end if
rs.AbsolutePage=Page
if page=maxpage then
x=iCount-(maxpage-1)*iPageSize
else
x=iPageSize
end if
%>
<tr>
<td bgcolor="#FFFFFF"><%'以下显示分页
call PageControl(iCount,maxpage,page,"border=0 align=center","<p align=center>")
rs.close
set rs=nothing
%></td>
</tr>
</table></td>
</tr>
<tr>
<td colspan="2"> </td>
</tr>
</table>
</tr>
<tr>
<td height="20">
<div style="border-bottom:#005AB5 5px solid;"></div></td>
</tr>
<!--#include file="foot.asp" -->
</body>
</html>
[解决办法]
dim i,i_psize,i_Page,i_RecordCount,i_PageCount
i_psize=5
i_Page=trim(Request.QueryString("pagenum"))
if not isNumeric(i_page)or i_page="" then
i_Page=1
else
i_page=CInt(i_page)
end if
Set rs = Server.CreateObject("adodb.Recordset")
sql = "select * from [Guestbook] Order by ID desc"
rs.Open sql,conn,1,1
If Rs.Eof And Rs.Bof Then
Response.write "暂无留言"
Else
i=0
Rs.PageSize=i_psize
i_RecordCount=Rs.RecordCount
i_PageCount=Rs.PageCount
If i_Page>i_PageCount Then i_Page=i_PageCount
Rs.AbsolutePage=i_Page
Do While Not Rs.Eof and i<Rs.PageSize
%>
希望对楼主有用。
[解决办法]