续:******朋友(denghai)帮忙,高分查看这段代码:查询关键字分页显示时,第一页正常,从第二页开始,就按

http://appserver/search.asp
企业客户基本資料文档
--------------------------------------------------------------------------------
客户名称: 公司 ------ 查询
首页显示:
http://appserver/search.asp

客户编号 客户名称 負責人 聯系人 EMAIL 网址 单位性质 地址 联系方式
搜索:公司
27003 新西兰凯威公司 蔡莉 上鼎1713 2659581 2659581(fax)
......

27016 司达福纺织有限公司 赵青 上鼎1711 2802532 2802536(fax)
本库共435个记录 首页 上一页下一页 尾页页次:1/44页 10个记录/页 第1页...第44页

第二页 显示:
http://appserver/search.asp?page=2&strname=公司

本库共689个记录 首页上一页下一页 尾页页次:2/69页 10个记录/页 第2页 ... 第69页

第3页(从此页开始,地址中strname没有值了
http://appserver/search.asp?page=3&strname=

本库共689个记录 首页上一页下一页 尾页页次:3/69页 10个记录/页 第3页 ... 第69页

http://appserver/search.asp?page=4&strname=

本库共689个记录 首页上一页下一页 尾页页次:4/69页 10个记录/页 第4页 ... 第69页

......

---------------------------------------------------------------

 1   
 2''''''''''连接数据库   
 3  
 4dim conn,connst   
 5'connstr= "provider=oraoledb.oracle.1;persist security info=true;user id=iagent;password=ia;data source=app_yong"   
 6'set conn=server.createobject("adodb.connection")   
 7'conn.open connstr   
 8  
 9'''''''''''''''''''''''''''''''''''''''''''''   
10'为方便调试,我把它换成了ACCESS   
11connstr="DBQ="+server.mappath("db3.mdb")+";DefaultDir=;DRIVER={Microsoft Access Driver (*.mdb)};"   
12set conn=server.createobject("ADODB.CONNECTION")   
13conn.open connstr   
14if trim(request("name"))="" then   
15strname=""   
16else   
17strname=trim(request("name") )'关键字   
18end if   
19MaxPerPage=2 '每页最多显示的记录数   
20if not isempty(request("page")) then   
21currentPage=cint(request("page")) '由上页传过来的页数   
22else   
23currentPage=1 '如果页数为空则为第一页   
24end if   
 1<html>
 2<head>
 3<title></title>
 4</head><body><form action="search.asp" method="Post">
 5<table border="0" cellpadding="0" cellspacing="0" topmargin="0" width="100%"><tr>
 6<td>           <font face="新細明體" size="5"><strong>                                 
 7企业客户基本資料文档</strong></font>             
 8<hr color="#000080" size="1"/>
 9<font color="Red"><font size="2">               
10</font></font> 客户名称:   
11<input id="name" name="name" size="20" type="text"/>
12<input name="Submit" type="submit" value="查询"/>
13</td>
14</tr>
15</table> </form>
16<table border="1" bordercolor="#999999" cellpadding="0" cellspacing="0" width="100%">
17<tr> <!---显示表头!--->
18<td align="center" width="64"><b><font color="#800000" size="2">客户编号</font></b></td>
19<td align="center" width="57"><b><font color="#800000" size="2">客户名称</font></b></td>
20<td align="center" width="53"><b><font color="#800000" size="2">負責人</font></b></td>
21<td align="center" width="49"><b><font color="#800000" size="2">聯系人</font></b></td>
22<td align="center" width="40"><b><font color="#800000" size="2">EMAIL</font></b></td>
23<td align="center" width="38"><b><font color="#800000" size="2">网址</font></b></td>
24<td align="center" width="85"> <b> <font color="#800000" size="2"> 单位性质</font>
25</b></td>
26<td align="center" width="67"> <b> <font color="#800000" size="2">邮编 </font>
27</b></td>
28<td align="center" width="313"> <b> <font color="#800000" size="2"> 联系方式</font>
29</b></td>
30</tr>   
31&lt;%   
32response.write "搜索:<font color="blue">"&amp;strname&amp;"</font>"   
33set rs=server.createobject("adodb.recordset")   
34'根据不同情况创建并打开记录集   
35if strname="" then   
36sql="select contactid,name,corporation,contact,email,webaddr,occupation, zipcode,allphn from contact"   
37else   
38sql="select contactid,name,corporation,contact,email,webaddr,occupation, zipcode,allphn from contact where name like '%"&amp;strname&amp;"%'"   
39end if   
40rs.open sql,conn,1,1   
41if rs.eof and rs.bof then '如果记录集为空   
42Response.Write "<font color="red">抱歉,没有搜索到相关的资料!</font>"   
43else '不为空   
44'Response.Write "共搜索到" &amp; rs.RecordCount &amp; "条相关资料,共"&amp; rs.PageCount &amp;"页,每页"&amp; rs.PageSize &amp;"条(当前第"&amp; Page &amp;"页)"   
45totalPut=rs.recordcount   
46if currentpage&lt;1 then '确定当前页码   
47currentpage=1   
48end if   
49  
50if (currentpage-1)*MaxPerPage&gt;totalput then   
51if (totalPut mod MaxPerPage)=0 then   
52currentpage= totalPut \ MaxPerPage   
53else   
54currentpage= totalPut \ MaxPerPage + 1   
55end if   
56end if   
57if currentPage=1 then   
58showContent   
59showpage totalput,MaxPerPage,"search.asp"   
60else   
61if (currentPage-1)*MaxPerPage&lt;totalPut then   
62rs.move (currentPage-1)*MaxPerPage   
63dim bookmark   
64bookmark=rs.bookmark   
65showContent   
66showpage totalput,MaxPerPage,"search.asp"   
67else   
68currentPage=1   
69showContent   
70showpage totalput,MaxPerPage,"search.asp"   
71end if   
72end if   
73rs.close   
74end if</table></body></html>
Published At
Categories with Web编程
comments powered by Disqus