分頁和查詢衝突?

reedchen 2003-12-16 09:45:47
請幫小弟看看原代碼,還是不會,謝謝先
<%@ Language=VBScript %>

<html>

<head>
<meta http-equiv="Content-Type" content="text/html; charset=big5">
<meta name="GENERATOR" content="Microsoft FrontPage 4.0">
<meta name="ProgId" content="FrontPage.Editor.Document">

</head>



<% emp=request("工號")
emp=ucase(emp)
%>
<%
Set Conne = Server.CreateObject("ADODB.Connection")
conne.open "Driver={Microsoft ODBC For Oracle};server=dnisfis; uid=sfis; pwd=sfis"
Set RS=Server.CreateObject("ADODB.RecordSet")


if (emp = "") then
sql= "select C.EMP,P.EMP_PASS,C.FUN,C.PRIVILEGE,C.PRG_NAME,P.EMP_NAME FROM SFIS1.C_PRIVILEGE C, SFIS1.C_EMP_DESC_T P WHERE C.EMP=P.EMP_NO order by C.EMP desc"


else
sql="select C.EMP,P.EMP_PASS,C.FUN,C.PRIVILEGE,C.PRG_NAME,P.EMP_NAME FROM SFIS1.C_PRIVILEGE C,SFIS1.C_EMP_DESC_T P where C.EMP='"&emp&"' AND P.EMP_NO=C.EMP "


end if
rs.open sql, conne, 3,3

%>


<%
dim maxpages

dim totalrecord

dim TotalPages




if not isempty(Request.QueryString("page")) then
thepage=cint(Request.QueryString("page"))
else
thepage=1
end if %>
<%

%>
<% if not rs.eof then '在最後結束
rs.PageSize=20
totalrecord=rs.RecordCount
' totalrecord=int(rs(0))

totalpages=rs.pagecount

maxpages=rs.pagesize


if thepage>totalpages or thepage<=0 then
thepage=1
showContent

else
rs.absolutepage=thepage

showContent
end if
rs.close
set rs=nothing
conne.close
set conne=nothing
%>



<%sub showContent%>





<% dim i
i=1 %>
<body>
<table border=0 width=100% bordercolor=#f1fce4 cellspacing=1 bgcolor=#bdf084 align=left style="table-layout:fixed" >

<TR bgcolor=#f1fce4 align=middle>
<TD bgcolor=#bdf084 width=10%><P align=center><FONT size=3>序號</FONT></P></TD>
<TD bgcolor=#bdf084 width=13%><P align=center><FONT size=3>工號</FONT></P></TD>
<TD bgcolor=#bdf084 width=13%><P align=center><FONT size=3>姓名</FONT></P></TD>
<TD bgcolor=#bdf084 width=13%><P align=center><FONT size=3>密碼</FONT></P></TD>
<TD bgcolor=#bdf084 width=23%><P align=center><FONT size=3>功能</FONT></P></TD>
<TD bgcolor=#bdf084 width=10%><P align=center><FONT size=3 >權限</FONT></P></TD>
<TD bgcolor=#bdf084><P align=center><FONT size=3 >站別</FONT></P></TD></tr>

<%
do while not rs.eof
%>



<tr bgcolor=#f1fce4>
<TD borderColor=#9400d3 width=90> <P align=center><FONT size=2><%=i %></FONT></P></TD>
<TD borderColor=#9400d3 width=90> <P align=center><FONT size=2><%=RS("EMP") %></FONT></P></TD>

<TD borderColor=#9400d3 width=90> <P align=center><FONT size=2><%=RS("EMP_NAME") %></FONT></P></TD>

<TD borderColor=#9400d3 width=60> <P align=center><FONT size=2><%=rs("EMP_PASS")%></FONT></P></TD>
<TD borderColor=#9400d3 width=160> <P align=center><FONT size=2><%=rs("FUN")%></FONT></P></TD>
<TD borderColor=#9400d3 width=90> <P align=center><FONT size=2><%=rs("PRIVILEGE")%></FONT></P></TD>
<TD borderColor=#9400d3 width=90> <P align=center><FONT size=2><%=rs("PRG_NAME")%></FONT></P></TD>

<% i=i+1
if i>=maxpages then%>
<% exit do%>
<%end if%></TR>

<% rs.movenext%>
<% loop%>


<% If thepage>=1 Then %>

<% showpages '顯示分頁情況 %>

<%end if%>


<% end sub%>

<%
else
response.write "<font size='4' color='#000000'>現在沒有內容。</font>"
rs.close
set rs=nothing
conne.close
set conne=nothing
end if
%>

<%

Sub showpages

if thepage=1 then

Response.Write "【首頁】"
Response.Write "【上一頁】"

else %>

<%
Response.Write "<A href=shopfind.asp>【首頁】</A>"

Response.Write "<A href=?Page=" & (thepage-1) &">【上一頁】</A>"%>

<% end if

if totalpages-thepage<1 then
Response.Write "【下一頁】"
Response.Write "【尾頁】"
else %>

<% Response.Write "<A href=shopfind.asp?Page=" & (thepage+1) &">【下一頁】</A>"
Response.Write "<A href=shopfind.asp?Page=" & totalPages &">【尾頁】</A>" %>

<%end if%>


<% Response.Write "【第<font color=#000000>" & thepage & "</font>頁】"

Response.Write "【共<font color=#000000> "&totalpages&" </font>頁】"

Response.Write "【共<font color=#ff0000>" & totalrecord & "</font>條記錄】"


End Sub



%>

</table>




</html>

...全文
150 15 打赏 收藏 转发到动态 举报
写回复
用AI写文章
15 条回复
切换为时间正序
请发表友善的回复…
发表回复
reedchen 2003-12-17
  • 打赏
  • 举报
回复
謝謝兩位樓主,已搞定了
yjhgmyyamd 2003-12-17
  • 打赏
  • 举报
回复
同意楼上的
lonaerd 2003-12-17
  • 打赏
  • 举报
回复
少了两个支持变量函数:
const MaxPerPage=18 ‘每页显示18条记录

function GetFlagnum(FlagNum) '判断currectpage 属于第几个大页
if cint(CurrectPage)<=FlagNum then
getflagnum=1
else

if (currectpage mod FlagNum)=0 then
getflagnum=currectpage\FlagNum
else
getflagnum=currectpage\FlagNum+1

end if


end if

end function


我用上面的代码套了无数个程序,从来没有任何问题
准备再封装一下写个完美的分页函数

lonaerd 2003-12-17
  • 打赏
  • 举报
回复
用什么SESSION啊,提交POST也可以啊,关键是你的分页没有写好!!看着了:

'***********分页变量***********
dim CurrectPage
dim RecNum
dim PageNum
dim PointFlag

dim k
k=0
RecNum=0
'************************
if request("PageNo")="" then
CurrectPage=1
else
CurrectPage=request("PageNo")
end if


dim rs
dim Keywords
dim FieldType

Keywords=trim(request("T1")) ‘查询关键字
FieldType=request("D1") ’查询关键项,为下拉框

if FieldType="" or Keywords="" then
set rs=opentable("select * from modle order by inputdate desc ",sqlconn)
else
if fieldtype="factoryid" then
set rs=opentable("select modle.* from factory inner join modle on factory.factoryid=modle.factoryid where factory.name like '%"&keywords&"%' order by inputdate desc",sqlconn)
else
set rs=opentable("select * from modle where "&fieldtype&" like '%"&keywords&"%' order by inputdate desc ",sqlconn)
end if

end if

'****************分页过程代码**************
if not rs.eof then
PointFlag=(CurrectPage-1)*MaxPerPage
rs.move(PointFlag)
RecNum=rs.recordcount
if (RecNum mod MaxPerPage)=0 then
PageNum=RecNum\MaxPerPage
else
PageNum=RecNum\MaxPerPage+1
end if
end if

Function OutPage(Num1,PageName,FlagNum) '输出分页码,num1为当前记录总数,PageName为当前页面名称
dim j
dim updown
dim downup
if Num1>=2 then
dim kk
dim countnum
countnum=0
kk=GetFlagnum(FlagNum)
if kk<2 then
updown=1
downup=FlagNum+1
else
updown=(kk-2)*flagnum+1
downup=kk*flagnum+1
end if
response.write "<font color='ff0000' style='font-size:14px'><a href="&pagename&"?PageNo="&updown&"&T1="&Keywords&"&D1="&FieldType&"><--</a></font>"&space(1)

for j=(kk-1)*flagnum+1 to num1
response.write "<font color='ff0000' style='font-size:14px'><a href="&pagename&"?PageNo="&j&"&T1="&Keywords&"&D1="&FieldType&">["&j&"]</a></font>"&space(1)
countnum=countnum+1
if countnum=flagnum+1 then exit for
next
response.write "<font color='ff0000' style='font-size:14px'><a href="&pagename&"?PageNo="&downup&"&T1="&Keywords&"&D1="&FieldType&">--></a></font>"&space(1)
end if
end function


调用 <%outpage pagenum “文件名.asp",8 %>

显示为 <--1 2 3 4 5 6 7 8-->
按右边的箭头将显示<--8 9 10 11 12 13 14 15 -->依次类推,假如记录足够多的话

超级大笨狼 2003-12-16
  • 打赏
  • 举报
回复


ASP学习史上最强的数据分页方法

  我观前辈的帖子,皆由于数据库的SQL大不一致,且SQL SERVER,ACCESS等菜鸟级数据库没有如rowid,_n_,obs等之类的辅助列,空有BETWEEN运算符而无用武之地,
又无如except之类的数据集运算符,真是令无数英雄尽折腰



  偶详观各数据库SQL,得出是数据库就有取前面N条记录的SQL语法,如什么select top n*****之类的语法,而数据分页的关键问题是取后N条记录的语法偶深思良久,最后小悟,故出此言,还忘前辈们多多指点
  
  取记录集后N条记录的大法:
  
  假设:
  
   1.有一sql语句将产生1000条记录 (select 唯一ID,其他字段 from 表集 where 条件 order by 排序)
   2.每页显示20条记录
   3.当前显示第5页
  
  实现如下:
   select * from
   (
   select * from (select top 20*4 唯一ID,其他字段 from 表集 where 条件 order by 排序) as a
   union all
   select * from (select top 20*5 唯一ID,其他字段 from 表集 where 条件 order by 排序) as b
   )
   a
   group by 唯一ID,其他字段 having count(唯一ID)=1 order by 排序
  
  运行此SQL,至此取记录集后N条记录大法就些完毕
  
  详细说明:
  
  此SQL语句的关键应用技巧在于union all和分组上的条件过滤语句
  
  大家可以根据此技巧完全可以做出一个通用的分页方法,如直接由用户传入sqlstr(sql语句),NumPerPage(每页显示数),currpage(当前页),自己在再函数内组织成通成的SQL分页语句
  
  备注:
  
  当前页为1的话就不需要运行该SQL了,直接TOP一下就OK了
  由于没有环境,该SQL性能无法测试,但相信不会低效
  运行平台在access,sqlserver上都可运行,其它数据库平台只需改top关键字应该就可以就地运行了






nevana 2003-12-16
  • 打赏
  • 举报
回复
用session把SQL里的参数保存起来,传到网页上面,用request.querystring()接下,在写到SQL里就可以了!
reedchen 2003-12-16
  • 打赏
  • 举报
回复
請教樓主查詢變量值怎麼傳呢,小弟愚昧,謝謝先,是否可以在上面的程序中標示一下.
wangjingyan 2003-12-16
  • 打赏
  • 举报
回复
你必须在 在翻页的时候将查询变量的值传递一下 并且form提交需要用get
zsd820830 2003-12-16
  • 打赏
  • 举报
回复
主要是因为你翻页时那个查询条件的值没有记住,最好是用session或者application定义一个变量来记住这个查询值,再用他来查询即可,试试看!
reedchen 2003-12-16
  • 打赏
  • 举报
回复
不好意思,就是查詢時,翻了第一頁後,第二頁就開始顯示全部的記錄和頁數,而不是只出現符合查詢條件的頁數和記錄數
zsd820830 2003-12-16
  • 打赏
  • 举报
回复
到底出现怎样的错误提示啊,详细说一下,这么长一段代码真的是懒得看了
reedchen 2003-12-16
  • 打赏
  • 举报
回复
不好意思,我用樓主的方法,好像還是不行呢,翻下一頁時查詢語句用到的參數被賦值為空了(顯示mp=
<A href=shopfind.asp?Page=" & (thepage+1) &"&mp="&session("mp") &">【下一頁】</A>
謝謝了

fogheart 2003-12-16
  • 打赏
  • 举报
回复
代码太多了,懒得看了,你在进行翻页的时候把查询语句用到的参数带上,就可以了
象这样的<A href=shopfind.asp?Page=" & (thepage+1) &">【下一頁】</A>链接在后面加个参数<A href=shopfind.asp?Page=" & (thepage+1) &"&emp="&request("emp") &">【下一頁】</A>
huejim 2003-12-16
  • 打赏
  • 举报
回复
reedchen 2003-12-16
  • 打赏
  • 举报
回复
請教nevana(金屬歌特)怎麼怎樣保存和傳遞呢,我好像不行呢
mp=request("工號")
session("mp")=mp
mp=session("mp")
sql="select C.EMP,P.EMP_PASS,C.FUN,C.PRIVILEGE,C.PRG_NAME,P.EMP_NAME FROM SFIS1.C_PRIVILEGE C , SFIS1.C_EMP_DESC_T P where C.EMP='"&mp&"' AND P.EMP_NO=C.EMP"
怎麼還是不行呢

28,407

社区成员

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

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