读书人

哪位高手能针对小弟我的这个查询给个能

发布时间: 2012-02-20 21:18:25 作者: rapoo

谁能针对我的这个查询给个能用的分页代码,谢谢~能用马上给分~~~
<%response.Buffer=true%>
<html>
<head>
<meta http-equiv= "Content-Type " content= "text/html; charset=gb2312 " />
<title> 需求单系统处理历史查询 </title>
</head>
<!--#include file= "conn.asp "-->
<script type= "text/javascript " src= "calendar.js "> </script>

<form action= "dispose_history.asp " method= "post " name= "dispose_history ">
<table width= "852 " border= "1 " align= "center ">
<td colspan= "4 " class= "titleClass "> 需求单系统查询画面 </td>
<tr>
<td width= "115 " height= "48 "> 需求主旨: </td>
<td colspan= "3 "> <label>
<input type= "text " id= "MAJOR_IDEA " name= "MAJOR_IDEA " size= "65 " maxlength= "65 " />
</label> </td>
</tr>
<tr>
<td height= "43 "> 需求单提出日期: </td>
<td width= "305 "> <label>
<input onFocus= "calendar() " name= "APPLY_TIME_start " type= "text " id= "APPLY_TIME_start " />
</label> </td>
<td width= "87 "> 至: </td>
<td width= "317 "> <label>
<input onFocus= "calendar() " name= "APPLY_TIME_end " type= "text " id= "Calendar1 " />
</label> </td>
</tr>
<tr>
<td height= "35 "> 希望上线时间: </td>
<td> <label>
<input onFocus= "calendar() " name= "WISH_FINISH_TIME_start " type= "text " id= "Calendar1 " />
</label> </td>
<td> 至: </td>
<td> <label>
<input onFocus= "calendar() " name= "WISH_FINISH_TIME_end " type= "text " id= "Calendar1 " />
</label> </td>
</tr>
<tr>
<td height= "42 "> 资讯主办: </td>
<td> <label>
<input name= "IT_UNDERTAKER " type= "text " size= "30 " />
</label> </td>
<td> 需求状态: </td>


<td> <label>
<select name= "PHASE " >
<option selected= "selected "> 请选择 </option>
<option value= "提单审核 "> 提单审核 </option>
<option value= "效益评估 "> 效益评估 </option>
<option value= "需求确认 "> 需求确认 </option>
<option value= "系统分析 "> 系统分析 </option>
<option value= "系统开发 "> 系统开发 </option>
<option value= "系统测试 "> 系统测试 </option>
<option value= "用户测试 "> 用户测试 </option>
<option value= "达成目标 "> 达成目标 </option>
<option value= "正式上线 "> 正式上线 </option>
</select>
</label> </td>
</tr>
<tr>
<td height= "41 " colspan= "4 "> 查询条件选择
<label>
<input type= "button " name= "select1 " value= "查询 " />
<input name= "reset " type= "button " onClick= "show(); return false; " value= "重置 " />
</label> </td>
</tr>
</table>
</tr>
</table>
<p>   </p>
<tr> <td colspan=4 width= "600 " height= "10 "> <input name=flag type=hidden value= " "> </td> </tr>


<TABLE cellPadding=1 align= "center " cellSpacing=1 align=center border=1 width= "900 " height= "1 " >
<%
response.write " <tr> "
response.write " <td width=100> 需求单位 </td> "
response.write " <td width=100> 主旨 </td> "
response.write " <td width=100> 资讯主办 </td> "
response.write " <td width=100> 预估完成日期 </td> "
response.write " <td width=100> 需求确认日期 </td> "
response.write " <td width=100> 分析完成日期 </td> "
response.write " <td width=100> 开发完成日期 </td> "


response.write " <td width=100> 测试完成日期 </td> "
response.write " <td width=100> 正式上线 </td> </tr> "
dim MAJOR_IDEA,APPLY_TIME_start,APPLY_TIME_end,WISH_FINISH_TIME_start,WISH_FINISH_TIME_end,IT_UNDERTAKER,PHASE
MAJOR_IDEA=Trim(request.form( "MAJOR_IDEA "))
APPLY_TIME_start=Trim(request.form( "APPLY_TIME_start "))
APPLY_TIME_end=Trim(request.form( "APPLY_TIME_end "))
WISH_FINISH_TIME_start=Trim(request.form( "WISH_FINISH_TIME_start "))
WISH_FINISH_TIME_end=Trim(request.form( "WISH_FINISH_TIME_end "))
IT_UNDERTAKER=Trim(request.form( "IT_UNDERTAKER "))
PHASE=Trim(request.form( "PHASE "))
Dim Rs,Sql
Set Rs = server.CreateObject( "Adodb.Recordset ")
if request( "flag ")= "Q " then
sql= "select APPLY_DEPARTMENT,MAJOR_IDEA,IT_UNDERTAKER,TOTESTTIME,RequireDate,TOTESTTIME,AnalysDate,CodeDate,TestDate,FINISH_TIME from songzw.REQUIRE_BILL where 1=1 "
if len(MAJOR_IDEA)> 0 then
sql=sql & " and MAJOR_IDEA like '% "& MAJOR_IDEA & "% ' "
end if
if len(APPLY_TIME_start)> 1 then
sql=sql & " and APPLY_TIME > = ' "& APPLY_TIME_start & " ' "
end if
if len(APPLY_TIME_end)> 1 then
sql=sql& " and APPLY_TIME <= ' "& APPLY_TIME_end & " ' "
end if
if len( WISH_FINISH_TIME_start)> 1 then
sql=sql& " and WISH_FINISH_TIME > = ' "& WISH_FINISH_TIME_start & " ' "
end if
if len(WISH_FINISH_TIME_end)> 1 then
sql=sql& " and APPLY_TIME <= ' "& WISH_FINISH_TIME_end & " ' "
end if
if len(IT_UNDERTAKER)> 1 then
sql=sql& " and IT_UNDERTAKE = ' "& IT_UNDERTAKE & " ' "
end if
if len(PHASE)> 3 then
sql=sql& " and PHASE= ' "& PHASE & " ' "
end if
sql=sql & " order by APPLY_TIME desc "
Rs.open SQL,CONN,1,1
if Not rs.Eof then
Rs.MoveFirst
else
response.Write( "需求单不存在 ")
end if

Do while Not rs.Eof
nAPPLY_DEPARTMENT=trim(rs.fields( "APPLY_DEPARTMENT "))
nMAJOR_IDEA=trim(rs.fields( "MAJOR_IDEA "))
nIT_UNDERTAKER=trim(rs.fields( "IT_UNDERTAKER "))
nTOTESTTIME=trim(rs.fields( "TOTESTTIME "))
nRequireDate=trim(rs.fields( "RequireDate "))


nAnalysDate=trim(rs.fields( "AnalysDate "))
nCodeDate=trim(rs.fields( "CodeDate "))
nTestDate=trim(rs.fields( "TestDate "))
nFINISH_TIME=trim(rs.fields( "FINISH_TIME "))


response.write " <tr> "
response.write " <td width=100> " & nAPPLY_DEPARTMENT & " </td> "
response.write " <td width=100> " & nMAJOR_IDEA & " </td> "
response.write " <td width=100> " & nIT_UNDERTAKER & " </td> "
response.write " <td width=100> " & nTOTESTTIME & " </td> "
response.write " <td width=100> " & nRequireDate & " </td> "
response.write " <td width=100> " & nAnalysDate & " </td> "
response.write " <td width=100> " & nCodeDate & " </td> "
response.write " <td width=100> " & nTestDate & " </td> "
response.write " <td width=100> " & nFINISH_TIME & " </td> </tr> "
Rs.MoveNext
Loop
end if
%>

</table>
</form>
</body>
</html>

<script language= "vbscript ">
dispose_history.MAJOR_IDEA.value= " <%=MAJOR_IDEA%> "
dispose_history.APPLY_TIME_start.value= " <%=APPLY_TIME_start%> "
dispose_history.APPLY_TIME_end.value= " <%=APPLY_TIME_end%> "
dispose_history.WISH_FINISH_TIME_start.value= " <%=WISH_FINISH_TIME_start%> "
dispose_history.WISH_FINISH_TIME_end.value= " <%=WISH_FINISH_TIME_end%> "
dispose_history. IT_UNDERTAKER.value= " <%= IT_UNDERTAKER%> "
dispose_history.PHASE.value= " <%=PHASE%> "
</script>


<script language= "vbscript " >
sub select1_onclick
if dispose_history.MAJOR_IDEA.value= " " and dispose_history.APPLY_TIME_start.value= " " and dispose_history.APPLY_TIME_end.value= " " and dispose_history.WISH_FINISH_TIME_start.value= " " and dispose_history.WISH_FINISH_TIME_end.value= " " and dispose_history.IT_UNDERTAKER.value= " " and dispose_history.PHASE.value= " " then
MsgBox "查询条件不能为空,至少需要输入一个查询条件! ",78, "需求单系统查询 "


dispose_history.MAJOR_IDEA.focus
exit sub
end if
dispose_history.flag.value= "Q "
dispose_history.submit
end sub
</script>


<script>
function show()
{
window.document.dispose_history.MAJOR_IDEA.value= " "
window.document.dispose_history.APPLY_TIME_start.value= " "
window.document.dispose_history.APPLY_TIME_end.value= " "
window.document.dispose_history.WISH_FINISH_TIME_start.value= " "
window.document.dispose_history.WISH_FINISH_TIME_end.value= " "
window.document.dispose_history.IT_UNDERTAKER.value= " "
window.document.dispose_history.PHASE.value= " "
}
</script>
<%
set Rs=nothing
Conn.close
Set Conn=nothing
%>




[解决办法]
<%
' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' '
' ' 功能完整的分页程序 + 高效SQL查询语句
' ' Power by Love_Computer
' ' love_computer@163.com
' ' www.56390.com
' ' 最后修改时间: 2005-05-26 12:28
' ' 使用过程中有任何问题请跟贴,及时答复。
' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' '

' ' ' ' '创建时间:2005-6-8 15:25 [love_computer@163.com]
' ' ' ' ' www.56390.com
' ' ' ' '最后修改时间 14:21 2005-8-30
' ' ' '获取总页数,总记录数
Sub ShowTotalPage()
Rem 以下内容直接COPY调用,不用任何修改
If Page = " " or IsEmpty(Page) = True or Page = "0 " or Page = Empty Then Page = 1
StrWhere = " "
If SearchWhere = " " Then
StrWhere = " "
Else
StrWhere = " WHERE " & SearchWhere
End If
StrTotal = "SELECT COUNT([ " & OnlyFieldName & "]) AS [rsTotal] FROM [ " & TableName & "] " & StrWhere
Set rsTotalRecord = Conn.Execute(StrTotal)
rsTotal = rsTotalRecord( "rsTotal ")
rsTotalRecord.Close:Set rsTotalRecord = Nothing
CurrentPage = Page
CurrentPage = Int(CurrentPage)
If rsTotal mod PageSizeNum = 0 Then
TotalPages = int(rsTotal \ PageSizeNum)
Else
TotalPages = int(rsTotal \ PageSizeNum) + 1
End If
If CurrentPage > TotalPages Then CurrentPage = TotalPages
Session( "rsTotal ") = rsTotal '总记录
Session( "TotalPages ") = TotalPages '总页数
Session( "CurrentPage ") = CurrentPage '当前页
End Sub

' ' ' ' ' ' ' ' ' ' ' ' '显示分页信息
' ' www.56390.com
Sub ShowPages(ShowListOrder,ShowSelect,ShowHidden)
If rsTotal <= PageSizeNum Then Exit Sub
StrURL = PageURL
If CurrentPage = 1 Then
PreviousPage = "首页 上页 "
Else
PreviousPage = " <a href= ' " & StrURL & "1 '> 首页 </a> <a href= ' " & StrURL & CurrentPage - 1 & " '> 上页 </a> "


End If
If CurrentPage = TotalPages Then
NextPage = "下页 末页 "
Else
NextPage = " <a href= ' " & StrURL & CurrentPage + 1 & " '> 下页 </a> <a href= ' " & StrURL & TotalPages & " '> 末页 </a> "
End If
ShowPageNum = " "
If ShowListOrder = 0 Then
If CurrentPage > 5 Then
xx = CurrentPage - 4
yy = CurrentPage + 5
Else
xx = 1
yy = 10
End If

For ii = xx TO yy
If ii > TotalPages Then Exit For
ShowPageNum = ShowPageNum & " <a href= ' " & StrURL & ii & " '> [ "
If ii = CurrentPage Then ShowPageNum = ShowPageNum & " <font color= '#FF0000 '> <b> "
ShowPageNum = ShowPageNum & ii
If ii = CurrentPage Then ShowPageNum = ShowPageNum & " </b> </font> "
ShowPageNum = ShowPageNum & "] </a> "
Next
End If

ShowTotal = "共 <font color= '#FF0000 '> <b> " & rsTotal & " </b> </font> 条记录 <font color= '#FF0000 '> <b> "
If ShowListOrder = 1 Then
ShowTotal = ShowTotal & CurrentPage & "/ "
End If
ShowTotal = ShowTotal & TotalPages & " </b> </font> 页 "
ShowTable = " <table width= '100% ' border= '0 ' cellspacing= '0 ' cellpadding= '0 '> "
If ShowSelect = 0 Then
ShowTable = ShowTable & " <form name= 'page ' method= 'get ' action= ' '> "
End If
ShowTable = ShowTable & " <tr> <td align= 'center ' valign= 'middle '> "
ShowTable = ShowTable & PreviousPage & " " & ShowPageNum & " " & NextPage & " " & ShowTotal & " "
Response.Write ShowTable
If ShowHidden = 0 Then
Call ShowHiddenText()
End If
ShowTable = " "
If ShowSelect = 0 Then
ShowTable = ShowTable & "转到 <select name= 'page ' onchange= 'this.form.submit() '> "
For n = 1 TO TotalPages
ShowTable = ShowTable & " <option value= ' " & n & " ' "
If n = CurrentPage Then ShowTable = ShowTable & " selected "
ShowTable = ShowTable & "> " & n & " </option> "
Next
ShowTable = ShowTable & " </select> 页 "
End If
ShowTable = ShowTable & " </td> </tr> "
If ShowSelect = 0 Then
ShowTable = ShowTable & " </form> "
End If
ShowTable = ShowTable & " </table> "
Response.Write ShowTable
End Sub


' ' ' ' ' ' '获取完整URL
' ' 来源于网上 好像是阿信的吧 具体不太清楚啦 HEHE
Function FullURL()
Dim strTemp
If LCase(Request.ServerVariables( "HTTPS ")) = "off " Then
strTemp = "http:// "
Else
strTemp = "https:// "
End If
strTemp = strTemp & Request.ServerVariables( "SERVER_NAME ")
If Request.ServerVariables( "SERVER_PORT ") <> 80 Then strTemp = strTemp & ": " & Request.ServerVariables( "SERVER_PORT ")
strTemp = strTemp & Request.ServerVariables( "URL ")
If Trim(Request.QueryString) <> " " Then strTemp = strTemp & "? " & Trim(Request.QueryString)
FullURL = strTemp
End Function

' ' ' ' ' ' ' ' ' '获取URL - 分页专用


' ' ' ' ' ' ' ' ' ' Power by Love_Computer...
' ' ' ' ' ' ' ' ' ' www.56390.com
Function PageURL()
URL = FullURL
TempUrl = Split(URL, "? ")
If ubound(TempUrl) = 0 then
URL = URL & "?page= "
Else
TempUrl = Split(URL, "?page= ")
If ubound(TempUrl) = 0 Then
TempUrl = Split(URL, "&page ")

URL = TempUrl(0) & "&page= "
Else
URL = TempUrl(0) & "?page= "
End If
End If
PageURL = URL
End Function

' ' ' ' ' ' ' ' ' ' ' '分页SQL语句函数
Function GetPageSQL(TableName,FieldName,SearchWhere,OrderFieldName,OnlyFieldName,OrderType,PageSizeNum,Page)
'Power by Love_Computer 2005-05-26 12:28
' www.56390.com
StrWhere = " "
StrOrder = " "
StrSQL = " "
MaxMinID = " "
If SearchWhere = " " Then
StrWhere = " "
MaxMinID = " WHERE ( [ " & OnlyFieldName & "] "
Else
StrWhere = " WHERE " & SearchWhere & " "
MaxMinID = " AND ( [ " & OnlyFieldName & "] "
End If
If OrderType = 0 Then
MaxMinID = MaxMinID & " > ( SELECT MAX "
StrOrder = " ORDER BY [ " & OrderFieldName & "] ASC "
Else
MaxMinID = MaxMinID & " < ( SELECT MIN "
StrOrder = " ORDER BY [ " & OrderFieldName & "] DESC "
End If
If Page = 1 or Page = 0 Then
StrSQL = "SELECT TOP " & PageSizeNum & " " & FieldName & " FROM [ " & TableName & "] " & StrWhere & StrOrder
Else
StrSQL = "SELECT TOP " & PageSizeNum & " " & FieldName & " FROM [ " & TableName & "] " & StrWhere & MaxMinID
StrSQL = StrSQL & " ([ " & OnlyFieldName & "]) FROM ( SELECT TOP "
StrSQL = StrSQL & PageSizeNum * (Page - 1) & " [ " & OnlyFieldName & "] FROM [ " & TableName & "] " & StrWhere & StrOrder
StrSQL = StrSQL & " ) AS TempTable ) ) " & StrOrder
End If
GetPageSQL = StrSQL
End Function
%>
<%
'Search
TableName = "News "
FieldName = " [id],[NewsTitle],[NewsType] "
SearchWhere = strWhere
OrderFieldName = "id "
OnlyFieldName = "id "
OrderType = 1
PageSizeNum = 27
Page = Trim(Request.QueryString( "page ")) : Call ShowTotalPage() : rsTotal = Session( "rsTotal ") : TotalPages = Session( "TotalPages ") : CurrentPage = Session( "CurrentPage ") : Session( "rsTotal ") = " " : Session( "TotalPages ") = " " : Session( "CurrentPage ") = " "
'SQL
PageSQL = GetPageSQL(TableName,FieldName,SearchWhere,OrderFieldName,OnlyFieldName,OrderType,PageSizeNum,CurrentPage)

'page
Call ShowPages(0,1,1)
%>
[解决办法]
<%
 If rs1.recordcount>0 Then ’ 记录集不为空则处理记录
  rs1.pagesize = 10 ’ 设置每页显示的记录数
  num=rs1.recordcount ’ 记录总数
  pagenum=rs1.pagecount ’ 页总数
  page=request( "page ") ’ 获取页码的原始信息
  ’ 处理页码原始信息的开始!
  If page <> " " then
   page = cint(page)
  if err.number <> 0 then
   err.clear


   page = 1
  end if
  if page < 1 then
   page = 1
  end if
 else
  page = 1
 End if
 if page*rs1.pagesize > num and not((page-1)*rs1.pagesize < num)then
  page=1
 end if
 ’ 处理页码原始信息的结束!设置当前页码
 rs1.absolutepage = page
%>
<!--判断当前页是否是最后一页,并根据判断设置记录的重复显示-->
<% if page<>pagenum then
   lablenum=rs1.pagesize
  else
   lablenum=num-(page-1)*rs1.pagesize
  end if
  for i=1 to lablenum
%>
<tr bgcolor= "#FFFFFF ">
 <td height= "25 "><div align= "center "><%=(rs1.Fields.Item( "id ").Value)%></div></td>
 <td><div align= "center "><%=(rs1.Fields.Item( "名称 ").Value)%></div></td>
 <td><div align= "center "><%=(rs1.Fields.Item( "地址 ").Value)%></div></td>
 <td><div align= "center "><%=(rs1.Fields.Item( "类别 ").Value)%></div></td>
 <td><div align= "center "><%=(rs1.Fields.Item( "最后修改 ").Value)%></div></td>
 <td><div align= "center "><%=(rs1.Fields.Item( "修改人 ").Value)%></div></td>
</tr>
<%
 rs1.movenext
next
%>
<!--当前页的记录显示结束,以下代码为记录集分页链接代码-->
<table width= "70% " border= "0 " align= "center " cellpadding= "0 " cellspacing= "0 ">
 <tr>
  <td height= "35 ">
   <div align= "right ">
    <font color= "#333333 ">
     共有 <%=num%> 个链接 |
     <a href=linkadmin.asp?page=1>首页</a> |
     <%if page>1 then%><a href=linkadmin.asp?page=<%=page-1%>><%end if%>上一页</a> |
     <%if page<pagenum then%><a href=linkadmin.asp?page=<%=page+1%>><%end if%>下一页</a> |
     <a href=linkadmin.asp?page=<%=pagenum%>>尾页</a> |
      页次:<%=page%>/<%=pagenum%>页 |
      共<%=pagenum%>页
    </font>
   </div>
  </td>
 </tr>
</table>
<!--记录集分页链接代码结束,记录集为空时执行以下代码-->
<%else%>
<tr bgcolor= "#FFFFFF ">
<td height= "25 " colspan= "6 "><div align= "center "><% response.Write( "没有结果可显示! ") %>
</div></td>
</tr>
<%
end if
rs1.Close()
Set rs1 = Nothing
%>


四:

<%set conn=server.createobject( "adodb.connection ")
conn.open "provider=microsoft.jet.oledb.4.0;data source= "& server.Mappath( "tupian.mdb ")
set rs=server.createobject( "adodb.recordset ")
sql= "select * from tu "
rs.open sql,conn,1,1
page=request.form( "page ")
if page= " " or isnull(page) then
page=1
end if
rs.pagesize=2
page=cint(page)
if page <1 then
page=1
elseif page> rs.pagecount then page=rs.pagecount
end if
rs.absolutepage=page
%>
<form name= "form1 " method= "post " action= "03.asp ">
<table width= "160 " border= "1 " align= "center ">
<%

do while not rs.eof and not rs.bof%>
<tr>
<td> <%=rs( "name ")%> </td>
</tr>
<%
rs.movenext
loop
%>
</table>
</form>
<div align= "center ">
<% if page <> 1 then%>
<a href= "03.asp?page=1 "> <font size= "2 "> 第一页 </font> </a>
<a href= "03.asp?page= <%=page-1%> "> <font size= "2 "> 上一页 </font> </a>


<%end if%>

<% if page <> rs.pagecount then%>
<a href= "03.asp?page= <%=page+1%> "> <font size= "2 "> 下一页 </font> </a>
<a href= "03.asp?page= <%=rs.pagecount%> "> <font size= "2 "> 最后一页 </font> </a>
<%end if%>
</div>

读书人网 >ASP

热点推荐