要实现的功能很简单:就是在文本框里输入一个值,然后查询数据库表中某字段等与这个值的记录,并把他们分页显示出来!
现在的问题是:第1页可以显示出来,但是点后面的第2页,第3页.....都没有结果(为空)!如果在SQL语句里直接指定WHERE=一个值,那就没问题!
<%@Language="VBSCRIPT" CODEPAGE="936"%>
<%
FileName:
Author:
Date:
Function:
Copyright:
Ver:1.0
dim Conn,strConn,RS,strsql
txtage=request.form("txtage")
strdsn="FILEDSN=student.dsn"
strsql="SELECT * FROM studentinfo where age="&txtage&""
dim intP,intPageSize,i
Set Conn = Server.CreateObject("ADODB.Connection")
conn.Open strdsn,"u12sgqy","u12sgqy"
Set RS = Server.CreateObject("ADODB.Recordset")
RS.Open strsql,Conn,1,1
if not RS.BOF then
If request.Form("pageindex") <> "" Then
intP = request.Form("pageindex")
Else
intP = 1
End If
dim intPageSize
intPageSize = 10
RS.PageSize = intPageSize页大小
RS.AbsolutePage = intp绝对位置
i = 0
DO while Not RS.EOF
i = i+1
If i > intPageSize Then Exit DO
Response.Write RS(0) & " " & RS(1) & " " & RS(2) & " " & RS(3) & "<BR>"
RS.MoveNext
Loop
Response.Write(getPage(RS.Recordcount,intP,intPageSize,5))这里调用的是我的一个分页函数,在csdn上我贴了
End If
RS.close
set rs = nothing
conn.close
set conn = nothing
%>
<%
功能:网页公共分页函数
参数:intCount int 总条数
intPageIndex int 当前页码
intPageSize int 每页大小
intShowNum int 每次显示分页数字的位数,例如< 1 2 3 4 > 等等
返回: 字符串,直接在网页上输出,字符串内容为一个表格组成的分页代码
作者:ji78
说明:本函数特点是于数据无关,直接输入数字即可完成,查询字符串自动判断,不需要特别添加
缺点是通过POST方式进行提交,刷新页面会出现提示框
使用方式: dim a
If Request.Form("pageindex")="" Then
a=1
else
a=Request.Form("pageindex")
End If
这里添加循环显示数据的信息
Response.Write(getPage(2000,a,10,6))
Response.Write(a)
日期:2003-9-8
Function GetPage(intCount,intPageIndex,intPageSize,intShowNum)
dim intPageCount,intP
计算出总页数
If intCount Mod intPageSize = 0 Then
intPageCount = intCount \ intPageSize
Else
intPageCount = intCount \ intPageSize + 1
End If
intP=(intPageIndex-1) \ intShowNum
输出验证输入数据的脚本
GetPage = "<SCRIPT LANGUAGE=""JavaScript""><!--"& VBLf &"function viewPage2(ipage){var test1=/^\d+$/;document.frmList2.pageindex.value=ipage;if (!test1.test(document.frmList2.pageindex.value)||document.frmList2.pageindex.value > "& intPageCount &"){alert(""输入的数字不正确"");return ;}else{document.frmList2.pageindex.value=ipage;document.frmList2.submit();}}"& VBLf &"//--></SCRIPT>"
判断是否有查询字符串出现
dim strAction
If Request.Servervariables("QUERY_STRING")="" Then
strAction=Request.ServerVariables("SCRIPT_NAME")
Else
strAction=Request.ServerVariables("SCRIPT_NAME") &"?"& request.serverVariables("QUERY_STRING")
End If
输出表格
GetPage = GetPage & "<table border=""0"" cellpadding=""0"" cellspacing=""3"" width=""100%""><tr>"
GetPage = GetPage & "<form name=""frmList2"" method=""Post"" action="""& strAction &""">"
getPage = GetPage & "<td valign=middle align=right><b>"& intPageIndex &"</b>/<b>"& intPageCount &"</b>页 <b>"& intPageSize &"</b>/<b>"& intCount &"</b>条 "
If intPageIndex = 1 Then
getPage = GetPage & "<font face=""webdings"">9</font> "
Else
getPage = GetPage & "<a href=""javascript:viewPage2("& Cstr(1) &")"" title=""首页""><font face=""webdings"">9</font></a> "
End If
If intP * 10 >0 Then
GetPage = GetPage & "<a href=""javascript:viewPage2("& Cstr(intP * intSHowNum) &")"" title=""前"& intShowNum &"页""><font face=""webdings"">7</font></a> "
End If
GetPage = GetPage & "<b>"
循环输出规定数目的数字
dim intI
For intI = (intP * intShowNum) +1 To (intP * intShowNum) +intShowNum
If Cstr(intI) = Cstr(intPageIndex) Then
GetPage = GetPage & Cstr(intI) &" "
Else
GetPage = GetPage & "<a href=""javascript:viewPage2("& Cstr(intI) &")"">"& intI &"</a> "
End If
If intI = intPageCount Then Exit For 判断是否最后一页并且不够规定条数
Next
GetPage = GetPage & "</b>"
If intI < intPageCount Then
GetPage = GetPage & "<a href=""javascript:viewPage2("& Cstr(intI) &")"" title=""下"& intShowNum &"页""><font face=""webdings"">8</font></a> "
End If
If Cstr(intPageIndex) = Cstr(intPageCount) Then
GetPage = GetPage & "<font face=""webdings"">:</font> "
Else
GetPage = GetPage & "<a href=""javascript:viewPage2("& Cstr(intPageCount) &")"" title=""尾页""><font face=""webdings"">:</font></a> "
End If
GetPage = GetPage & "<input type=""text"" name=""pageindex"" size=""2"" maxlength=""4"" value="""& intPageIndex &""" style=""COLOR: #000000; background-color: #FFFFFF; CURSOR: text; FONT-FAMILY: ""宋体"", ""Tahoma""; FONT-SIZE: 12px;HEIGHT:12pt;border:1px inset #EEEEEE;""> <input type=""button"" align=""absbottom"" onclick=""javascript:return viewPage2(document.frmList2.pageindex.value)"" value=""GO""></td></tr></form></table>"
End Function
%>
请指教!如解决了,送500分!
你调通了就告诉我一下.我 他在自己机器上和你布置了一个一样的环境.建立了一样的表和查询条件再调试的.我机器上通了代码如下
<%@Language="VBSCRIPT" CODEPAGE="936"%>
<%
FileName:
Author:
Date:
Function:
Copyright:
Ver:1.0
dim Conn,strConn,RS,strsql
txtage=request("txtage")
strdsn="FILEDSN=student.dsn"
strsql="SELECT * FROM studentinfo where age="&txtage&""
dim intP,intPageSize,i
Set Conn = Server.CreateObject("ADODB.Connection")
conn.Open strdsn,"u12sgqy","u12sgqy"
Set RS = Server.CreateObject("ADODB.Recordset")
RS.Open strsql,Conn,1,1
if not RS.BOF then
If request.Form("pageindex") <> "" Then
intP = request.Form("pageindex")
Else
intP = 1
End If
dim intPageSize
intPageSize = 10
RS.PageSize = intPageSize页大小
RS.AbsolutePage = intp绝对位置
i = 0
DO while Not RS.EOF
i = i+1
If i > intPageSize Then Exit DO
Response.Write RS(0) & " " & RS(1) & " " & RS(2) & " " & RS(3) & "<BR>"
RS.MoveNext
Loop
Response.Write(getPage(RS.Recordcount,intP,intPageSize,5))这里调用的是我的一个分页函数,在csdn上我贴了
End If
RS.close
set rs = nothing
conn.close
set conn = nothing
%>
<%
功能:网页公共分页函数
参数:intCount int 总条数
intPageIndex int 当前页码
intPageSize int 每页大小
intShowNum int 每次显示分页数字的位数,例如< 1 2 3 4 > 等等
返回: 字符串,直接在网页上输出,字符串内容为一个表格组成的分页代码
作者:ji78
说明:本函数特点是于数据无关,直接输入数字即可完成,查询字符串自动判断,不需要特别添加
缺点是通过POST方式进行提交,刷新页面会出现提示框
使用方式: dim a
If Request.Form("pageindex")="" Then
a=1
else
a=Request.Form("pageindex")
End If
这里添加循环显示数据的信息
Response.Write(getPage(2000,a,10,6))
Response.Write(a)
日期:2003-9-8
Function GetPage(intCount,intPageIndex,intPageSize,intShowNum)
dim intPageCount,intP
计算出总页数
If intCount Mod intPageSize = 0 Then
intPageCount = intCount \ intPageSize
Else
intPageCount = intCount \ intPageSize + 1
End If
intP=(intPageIndex-1) \ intShowNum
输出验证输入数据的脚本
GetPage = "<SCRIPT LANGUAGE=""JavaScript""><!--"& VBLf &"function viewPage2(ipage){var test1=/^\d+$/;document.frmList2.pageindex.value=ipage;if (!test1.test(document.frmList2.pageindex.value)||document.frmList2.pageindex.value > "& intPageCount &"){alert(""输入的数字不正确"");return ;}else{document.frmList2.pageindex.value=ipage;document.frmList2.submit();}}"& VBLf &"//--></SCRIPT>"
判断是否有查询字符串出现
dim strAction
If Request.Servervariables("QUERY_STRING")="" Then
strAction=Request.ServerVariables("SCRIPT_NAME")
Else
strAction=Request.ServerVariables("SCRIPT_NAME") &"?"& request.serverVariables("QUERY_STRING")
End If
输出表格
GetPage = GetPage & "<table border=""0"" cellpadding=""0"" cellspacing=""3"" width=""100%""><tr>"
GetPage = GetPage & "<form name=""frmList2"" method=""Post"" action="""& strAction &""">"
getPage = GetPage & "<td valign=middle align=right><b>"& intPageIndex &"</b>/<b>"& intPageCount &"</b>页 <b>"& intPageSize &"</b>/<b>"& intCount &"</b>条 "
If intPageIndex = 1 Then
getPage = GetPage & "<font face=""webdings"">9</font> "
Else
getPage = GetPage & "<a href=""javascript:viewPage2("& Cstr(1) &")"" title=""首页""><font face=""webdings"">9</font></a> "
End If
If intP * 10 >0 Then
GetPage = GetPage & "<a href=""javascript:viewPage2("& Cstr(intP * intSHowNum) &")"" title=""前"& intShowNum &"页""><font face=""webdings"">7</font></a> "
End If
GetPage = GetPage & "<b>"
循环输出规定数目的数字
dim intI
For intI = (intP * intShowNum) +1 To (intP * intShowNum) +intShowNum
If Cstr(intI) = Cstr(intPageIndex) Then
GetPage = GetPage & Cstr(intI) &" "
Else
GetPage = GetPage & "<a href=""javascript:viewPage2("& Cstr(intI) &")"">"& intI &"</a> "
End If
If intI = intPageCount Then Exit For 判断是否最后一页并且不够规定条数
Next
GetPage = GetPage & "</b>"
If intI < intPageCount Then
GetPage = GetPage & "<a href=""javascript:viewPage2("& Cstr(intI) &")"" title=""下"& intShowNum &"页""><font face=""webdings"">8</font></a> "
End If
If Cstr(intPageIndex) = Cstr(intPageCount) Then
GetPage = GetPage & "<font face=""webdings"">:</font> "
Else
GetPage = GetPage & "<a href=""javascript:viewPage2("& Cstr(intPageCount) &")"" title=""尾页""><font face=""webdings"">:</font></a> "
End If
GetPage = GetPage & "<input type=""hidden"" name=""txtage"" value=""" &txtage& """ >"
GetPage = GetPage & "<input type=""text"" name=""pageindex"" size=""2"" maxlength=""4"" value="""& intPageIndex &""" style=""COLOR: #000000; background-color: #FFFFFF; CURSOR: text; FONT-FAMILY: ""宋体"", ""Tahoma""; FONT-SIZE: 12px;HEIGHT:12pt;border:1px inset #EEEEEE;""> <input type=""button"" align=""absbottom"" onclick=""javascript:return viewPage2(document.frmList2.pageindex.value)"" value=""GO""></td></tr></form></table>"
End Function
%>