请问有关搜索中的分页问题

tcpc2003 2004-05-07 11:27:37
搜索的结果页面根据搜索的条件生成相应的SQL再进行查询及分页 请问这时怎么分页 主要问题是那个搜索的SQL如何传递???

...全文
105 15 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
15 条回复
切换为时间正序
请发表友善的回复…
发表回复
dullwolf 2004-07-08
  • 打赏
  • 举报
回复
这个价值超过200分
巨快,分页演示,通用表维护
http://www.adr.gov.cn/download/panyuguang/adrnew/dict_List.asp
下载
http://www.adr.gov.cn/download/panyuguang/adrnew.rar

fashchina 2004-06-21
  • 打赏
  • 举报
回复
思考。。。ing!
tcpc2003 2004-06-21
  • 打赏
  • 举报
回复
这样sql也显示在外面,,容易外泄一些库结构信息...
  • 打赏
  • 举报
回复
用url吧~~~你管它长不长的呢,实现功能就成了,^_^~~
tcpc2003 2004-05-10
  • 打赏
  • 举报
回复
session同一个客户端就有些问题...(一个用户打开两个同一页面)
cookies又有客户端的限制.......
tcpc2003 2004-05-09
  • 打赏
  • 举报
回复
上面这个例子它的SQL好象是固定的吧,但是查询时其SQL是变化,便通常分页又是写成函数,所以SQL中需要的参数也不好固定,所以也不好传到分页的函数中去。。。

思考。。。中....
nssp 2004-05-08
  • 打赏
  • 举报
回复
在下一页的链接地址中附上你所有需要的参数,如:
<a href="?page=2&keyword=111&stype=2">下一页</a>
amwje123 2004-05-08
  • 打赏
  • 举报
回复
楼上的好强哦!! 有你的就不用我的了 哈哈 开玩笑..
stanleycheung 2004-05-08
  • 打赏
  • 举报
回复
在分页显示中最好用URL传递参数
完整分页显示的示例,我的习惯是写两个页面
自己做适当修改
index.asp
<%@LANGUAGE="VBSCRIPT" CODEPAGE="936"%>
<!--#include file="../inc/dbconn.inc" -->
<%
Set rs=Server.CreateObject("ADODB.Recordset")
sql="Select * From gb Order By id Desc"
rs.Open sql,conn,1,1
currentPage=Request.QueryString("page") '当前页面
If Not IsEmpty(currentPage) Then
currentPage=CInt(currentPage)
Else
currentPage=1
End If
%>

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>guestbook</title>
<link href="../css/index_main.css" rel="stylesheet" type="text/css">
<style type="text/css">
<!--
.border01 {
border-bottom: 1px dotted #999999;
}
-->
</style>
</head>

<body oncontextmenu="window.event.returnValue=false;" onselectstart="window.event.returnValue=false;" ondragstart="window.event.returnValue=false;" onLoad="window.status='chinese patient';">
<br>
<table width="500" border="0" align="center" cellpadding="3" cellspacing="0">
<tr>
<td></td>
</tr>
<tr>
<td>
<% If rs.BOF And rs.EOF Then %>
<div align="center">no message</div>
<%
Else
rs.PageSize=8 '设置每页显示8条记录
totalPut=rs.RecordCount '记录总数
totalPage=rs.PageCount '页面总数
MaxPerPage=rs.PageSize '每页最大记录数
If currentpage<1 Then
currentpage=1
End If
If currentpage>totalPage Then
currentpage=totalPage
End If
If currentPage=1 Then
showpages
showContent
showpages
Else
If (currentPage-1)*MaxPerPage<totalPut Then
rs.Move (currentPage-1)*MaxPerPage
Dim bookmark
bookmark=rs.BookMark '移动到开始显示的记录位置
showpages
showContent
showpages
End If
End If
rs.Close
End If
Set rs=Nothing
conn.Close
Set conn=Nothing

Sub showContent
Dim i,k
k=(totalPut-MaxPerPage*(currentPage-1))+1
i=0
Do While Not (rs.EOF Or Err)
k=k-1
%>
</td>
</tr>
<tr>
<td>No.<%= k %></td>
</tr>
<tr>
<td><table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="100" class="font8pt"><%= rs("name") %></td>
<td width="400" class="font8pt"><%= rs("text") %></td>
</tr>
</table></td>
</tr>
<tr>
<td><table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="20%">
<% If rs("homepage")="還沒有主頁!" Then %>
<a href="javascript:alert('還沒有主頁!');" title="homepage: <%= rs("homepage") %>">homepage</a>
<% Else %>
<a href="<%= rs("homepage") %>" title="homepage: <%= rs("homepage") %>" target="_blank">homepage</a>
<% End If %>
</td>
<td width="20%">
<% If rs("email")="還沒有電郵!" Then %>
<a href="javascript:alert('還沒有電郵!');" title="email: <%= rs("email") %>">email</a>
<% Else %>
<a href="mailto:<%= rs("email") %>" title="email: <%= rs("email") %>">email</a>
<% End If %>
</td>
<td width="20%"> </td>
<td width="40%"> <div align="right">time: <%= rs("time") %></div></td>
</tr>
</table></td>
</tr>
<tr>
<td><table width="100%" border="0" cellspacing="0" cellpadding="0" class="border01">
<tr>
<td width="100"><font color="#666666">reply:</font></td>
<td width="400"><font color="#666666"><span class="font8pt"><%= rs("answer") %></span></font></td>
</tr>
</table></td>
</tr>
<tr>
<td>
<%
i=i+1
If i>=MaxPerPage Then Exit Do '循环时如果到尾部则先退出,如果记录达到页最大显示数,也退出
rs.MoveNext
Loop
End Sub

Sub showpages()
Dim n
n=totalPage
%>
</td>
</tr>
<tr>
<td class="border01"> pages:
<%
If currentPage<>1 Then
Response.Write("<a href='index.asp?page="&(currentPage-1)&"'><font face='宋体' size='1'><< </font></a>")
End If
If rs.PageCount<=8 Then
For i=1 To rs.PageCount
Response.Write("[<a href='index.asp?page="&i&"'>"&i&"</a>]")
Next
Else
For i=1 To 8
Response.Write("[<a href='index.asp?page="&i&"'>"&i&"</a>]")
Next
End If
If currentPage<>rs.PageCount Then
Response.Write("<a href='index.asp?page="&(currentPage+1)&"'><font face='宋体' size='1'> >></font></a>")
End If
%>
     
total pages: [<%= totalPage %>]
<% End Sub %>
</td>
</tr>
</table>
<table width="500" border="0" align="center" cellpadding="3" cellspacing="0">
<form method="post" action="savedata.asp">
<tr>
<td><br><br></td>
</tr>
<tr>
<td>name:
<input name="uname" type="text" class="text" size="10" value="<%= Session("uname") %>"></td>
</tr>
<tr>
<td>e-mail:
<input name="uemail" type="text" class="text" size="20"></td>
</tr>
<tr>
<td> homepage:
<input name="uhp" type="text" class="text" value="http://" size="25"></td>
</tr>
<tr>
<td><p>content:<br>
<textarea name="utext" cols="60" rows="10" class="textarea"></textarea>
</p>
<p>
<input name="submit" type="submit" value="submit" class="button">
   
<input name="reset" type="reset" value="reset" class="button">
</p>
</td>
</tr>
</form>
</table>
<!--#include file="../inc/copyright.js"-->
</body>
</html>

savedata.asp
<!--#include file="../inc/char.inc" -->
<!--#include file="../inc/dbconn.inc" -->
<%
Dim uname,uemail,uhp,uip,utext,sql,strHTML
uname=Request.Form("uname")
uemail=Request.Form("uemail")
uhp=Request.Form("uhp")
uip=Request.ServerVariables("REMOTE_ADDR")
utext=Request.Form("utext")
If uname=Empty Or utext=Empty Then
strHTML="<body bgcolor='#CCCCCC' scroll='no' oncontextmenu='window.event.returnValue=false;' onselectstart='window.event.returnValue=false;' ondragstart='window.event.returnValue=false;' onLoad='window.status=chinese patient;'><br><br><br><br><br><div align='center'><font face='Verdana' size='1' color='#990000'>please enter name and content<br><a href='index.asp'><font face='Verdana' size='1' color='#333333'>back</font></a></font></div></body>"
Response.Write(strHTML)
Response.End()
End If
Set rs=Server.CreateObject("ADODB.Recordset")
sql="Select * From gb"
rs.Open sql,conn,3,3
rs.AddNew
rs("name")=htmlencode2(uname)
If uemail<>Empty Then
rs("email")=htmlencode2(uemail)
Else
rs("email")="還沒有電郵!"
End If
If uhp="http://" Then
rs("homepage")="還沒有主頁!"
Else
rs("homepage")=htmlencode2(uhp)
End If
rs("ip")=htmlencode2(uip)
rs("text")=htmlencode2(utext)
rs("time")=Now()
rs.Update
rs.Close
Set rs=Nothing
conn.Close
Set conn=Nothing
Response.Redirect("index.asp")
%>
tcpc2003 2004-05-07
  • 打赏
  • 举报
回复
session,,cookies不太好,,有限制

hidden也不行呀 因为我分页后再瞧下一页时不是提交表单 而是联接..
url也太长了吧 不太好

有没有其它方法呢
stayhere 2004-05-07
  • 打赏
  • 举报
回复
用Hidden域传递,用Request.querystring传递,用SESSION传递,还有cookies...自己选吧
lightsword 2004-05-07
  • 打赏
  • 举报
回复
这个搜索条件的值必须传递,不传递的话值就没了,可以用URL传值.
chang1216 2004-05-07
  • 打赏
  • 举报
回复
对rscyc1这个结果集 进行分页!!
chang1216 2004-05-07
  • 打赏
  • 举报
回复
<input type="text" name="搜索的参数" size="30" value="<%=request("搜索的参数")%>">

sql="select * from youtable where 搜索的参数 like '%"&request("搜索的参数")&"%' "
set rscyc1=server.createobject("adodb.recordset")
rscyc1.open sql,conn,3,1
就可以了!!!
tcpc2003 2004-05-07
  • 打赏
  • 举报
回复
??

28,409

社区成员

发帖
与我相关
我的任务
社区描述
ASP即Active Server Pages,是Microsoft公司开发的服务器端脚本环境。
社区管理员
  • ASP
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧