| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 783 人关注过本帖
标题:asp查询分页浏览代码的错误在哪?
只看楼主 加入收藏
ak168
Rank: 1
等 级:新手上路
帖 子:3
专家分:0
注 册:2006-12-5
收藏
 问题点数:0 回复次数:3 
asp查询分页浏览代码的错误在哪?

我在百度搜索才找到这里,这里应该是asp的天堂,有个问题求助大家帮助!

下面是一个“员工资料查询”的小程序,其他正常就是分页有问题,下面是首页代码index.asp,程序浏览必须index.asp?action=so这样,查询index.asp?action=soend都正常,分页index.asp?page=2,但分页有问题,点击下一页没有任何内容,大家分析一下弊病在那里?

<!--#include file="top.asp" -->
<script language="JavaScript">
<!--
function openwin1(url)
{
window.open(url,"_blank","height=350,width=320,resizable=no,scrollbars=yes,statue=no,toolbar=no,menubar=no,location=no,left=150,top=80");
}
// -->
</script>

<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
</head>

<table width="100%" cellspacing="0" cellpadding="0">
<tr>
<td><table width="801" align="right" cellpadding="0" cellspacing="0">
<tr>
<td bgcolor="#D7D7D7"></td>
<td height="630" valign="top"><table width="618" cellspacing="0" cellpadding="0">
<tr>
<td></td>
</tr>
<tr>
<td align="center"><table width="96%" cellpadding="1" cellspacing="1">
<tr>
<td class="t"><br>
<%
Dim Action
Action=trim(request("Action"))
select case Action
case "so"
call Showso()
case "soend"
call soend()
end select
sub showso()
%>
<TABLE width="100%" border=0 align=center cellPadding=0 cellSpacing=1 bgcolor="#e7e7e7">
<TR>
<TD height="25" background="images/gradx.gif"><IMG height=16 src="images/blue_point.gif" width=16 align=absMiddle>员工身份查询</TD>
</TR>
<TR>
<TD bgcolor="#FFFFFF"><TABLE cellSpacing=0 cellPadding=6 width="100%" border=0>
<FORM name=form1 action=?action=soend method=post>
<TR>
<TD bgColor=#ffffff height=115>为了让您安全地购买本公司服务,您可以在此处查询公司员工资料,以鉴别其是否真实可靠。<br>
<br>
请输入员工姓名:
<INPUT name=key id="key">
<select name="search" size="1">
<option value="">请选择分类</option>
<option value="realname">按真实姓名</option>
<option value="sn">按员工编号</option>
<option value="tel">按电话号码</option>
</select>
<INPUT type=submit value=查询 name=Submit></TD>
</TR>
</FORM>
</TABLE>
</TD>
</TR>
</TABLE>
<%
end sub
sub soend()
%>
<TABLE width="100%" border=0 align=center cellPadding=0 cellSpacing=1 bgcolor="#e7e7e7">
<TR>
<TD height="25" background="images/gradx.gif"><IMG height=16 src="images/blue_point.gif" width=16 align=absMiddle>重新查询</TD>
</TR>
<FORM name=form1 action=?action=soend method=post>
<TR>
<TD height="30" bgcolor="#FFFFFF"> 请输入员工姓名:
<INPUT name=key id="key">
<select name="search" size="1">
<option value="">请选择分类</option>
<option value="realname">按真实姓名</option>
<option value="sn">按员工编号</option>
<option value="tel">按电话号码</option>
</select>
<INPUT type=submit value=查询 name=Submit></TD>
</TR>
</form>
</TABLE>
<br>
<TABLE width="100%" border=0 align=center cellPadding=0 cellSpacing=1 bgcolor="#e7e7e7">
<TR>
<TD height="25" background="images/gradx.gif"><IMG height=16 src="images/blue_point.gif" width=16 align=absMiddle>员工查询结果</TD>
</TR>
<TR>
<TD bgcolor="#FFFFFF"><br>
<%
dim strFileName
strFileName="index.asp"
pageno=10
dim sql,rs
dim search
sql="select * from staff"
if trim(request.Form("key"))<>"" then
if request("search")="realname" then
sql=sql&" where realname like '%"&trim(request.Form("key"))&"%'"
elseif request("search")="sn" then
sql=sql&" where sn like '%"&trim(request.Form("key"))&"%'"
elseif request("search")="tel" then
sql=sql&" where tel like '%"&trim(request.Form("key"))&"%'"
elseif request("search")="" then
sql=sql&" where realname like '%"&trim(request.Form("key"))&"%' or sn like '%"&trim(request.Form("key"))&"%' or business like '%"&trim(request.Form("key"))&"%' or branch like '%"&trim(request.Form("key"))&"%' or tel like '%"&trim(request.Form("key"))&"%' or mail like '%"&trim(request.Form("key"))&"%'"
end if
else
response.redirect"?Action=so"
end if
sql=sql&" order by SortNum asc"
set rs=server.CreateObject("adodb.recordset")
rs.open sql,conn,1,1
rscount=rs.recordcount
%>
<%if rscount<1 then%>
<table width="98%" border="0" align="center" cellpadding="0" cellspacing="1" class="tablecolor">
<tr>
<td height="25" colspan="8" align="center" class="tablebody"><%If request.Form("key")<>"" then%>
对不起,没有您所要查询的员工数据,请来此查询www.52725.com
<%
else
%>
没有员工数据!
<%End If%></td>
</tr>
</table>
<%else%>
<table width="98%" border="0" align="center" cellpadding="0" cellspacing="1" bgcolor="#00CCFF" class="tablecolor">
<tr bgcolor="#CAF4FF">
<td width="12%" height="25" align="center" background="images/st_bg.gif">真实姓名</td>
<td width="21%" align="center" background="images/st_bg.gif">员工编号</td>
<td width="16%" align="center" background="images/st_bg.gif">职务</td>
<td width="16%" align="center" background="images/st_bg.gif">部门</td>
<td width="20%" align="center" background="images/st_bg.gif">电话号码</td>
<td width="14%" align="center" background="images/st_bg.gif">上岗日期</td>
</tr>
<form name="form2" method="post" action="?action=edit" onSubmit="return checkf(form2)">
<%
call showsql(pageno)
rs.move(rsno)
for i=1 to loopno
%>
<tr bgcolor="#FFFFFF" >
<td height="25" align="center"><a href="javascript:openwin1('showstaff.asp?uid=<%=rs("id")%>')"><%=rs("realname")%></a></td>
<td align="center"><%=rs("sn")%></td>
<td align="center"><%=rs("business")%></td>
<td align="center"><%=rs("branch")%></td>
<td align="center"><%=rs("Tel")%></td>
<td align="center"><%=rs("duty")%></td>
</tr>
<%
rs.movenext
next
%>
</form>
<tr bgcolor="#FFFFFF">
<td colspan="6" align="right"><%call showpage(strFileName,rscount,pageno,true,true,"位员工")%></td>
</tr>
</table>
<%end if%><br></TD>
</TR>
</TABLE>
<%end sub%>
<br></td>
</tr>

</table></td>
</tr>
</table></td>
</tr>
</table></td>
</tr>
</table>




搜索更多相关主题的帖子: asp 代码 浏览 查询 
2006-12-05 08:54
ak168
Rank: 1
等 级:新手上路
帖 子:3
专家分:0
注 册:2006-12-5
收藏
得分:0 
这是相关分页控制的代码:

<%
dim pageno,pagemax,rscount,rsno,loopno,i,page
'---------------------检查用户名密码-------------------------------
function Checkin(s)
s=trim(s)
s=replace(s," ","&amp;nbsp;")
s=replace(s,"'","&amp;#39;")
s=replace(s,"""","&amp;quot;")
s=replace(s,"&lt;","&amp;lt;")
s=replace(s,"&gt;","&amp;gt;")
Checkin=s
end function
'--------------------------------------------
Rem 过滤SQL非法字符
function checkStr(str)
if isnull(str) then
checkStr = ""
exit function
end if
checkStr=replace(str,"'","''")
end function

'-------------------------------------

Rem 过滤HTML代码
function HTMLcode(fString)
if not isnull(fString) then
fString = replace(fString, ">", "&gt;")
fString = replace(fString, "<", "&lt;")

fString = Replace(fString, CHR(32), "&nbsp;")
fString = Replace(fString, CHR(9), "&nbsp;")
fString = Replace(fString, CHR(34), "&quot;")
fString = Replace(fString, CHR(39), "&#39;")
fString = Replace(fString, CHR(13), "")
fString = Replace(fString, CHR(10) & CHR(10), "</P><P> ")
fString = Replace(fString, CHR(10), "<BR> ")

HTMLEncode = fString
end if
end function

'--------------------------------------
Rem 过滤表单字符
function HTMLcode(fString)
if not isnull(fString) then
fString = Replace(fString, CHR(13), "")
fString = Replace(fString, CHR(10) & CHR(10), "</P><P>")
fString = Replace(fString, CHR(10), "<BR>")
HTMLcode = fString
end if
end function

'---------------------检查真实姓名----------------------------
function isChinese(para)
on error resume next
dim str
dim i
if isNUll(para) then
isChinese=false
exit function
end if
str=cstr(para)
if trim(str)="" then
isChinese=false
exit function
end if
for i=1 to len(str)
c=asc(mid(str,i,1))
if c>=0 then
isChinese=false
exit function
end if
next
isChinese=true
if err.number<>0 then err.clear
end function

'---------------------检查用户Email-------------------------------
function IsValidEmail(email)
dim names,name,c
IsValidEmail = true
names = Split(email, "@")
if UBound(names) <> 1 then
IsValidEmail = false
exit function
end if
for each name in names
if Len(name) <= 0 then
IsValidEmail = false
exit function
end if
for i = 1 to Len(name)
c = Lcase(Mid(name, i, 1))
if InStr("abcdefghijklmnopqrstuvwxyz_-.", c) <= 0 and not IsNumeric(c) then
IsValidEmail = false
exit function
end if
next
if Left(name, 1) = "." or Right(name, 1) = "." then
IsValidEmail = false
exit function
end if
next
if InStr(names(1), ".") <= 0 then
IsValidEmail = false
exit function
end if
i = Len(names(1)) - InStrRev(names(1), ".")
if i <> 2 and i <> 3 then
IsValidEmail = false
exit function
end if
if InStr(email, "..") > 0 then
IsValidEmail = false
end if

end function
'**************************************************
'函数名:shosql
'作 用:分页效果
'参 数:spage ----当前页
'参 数:spageno ----每页数量
'参 数:srscount ---数据总数
'**************************************************
sub showsql(spageno)
page=request("page")
if page="" or not isnumeric(page) then
page=1
else
page=clng(page)
end if
pageno=spageno
if page<1 then
page=1
end if

rscount=rscount

pagemax=rscount\pageno
if rscount mod pageno <>0 then
pagemax=pagemax+1
end if
if page>pagemax then
page=pagemax
end if
rsno=pageno*page-pageno
if page=pagemax then
loopno=rscount-rsno
else
loopno=pageno
end if
end sub

'**************************************************
'函数名:JoinChar
'作 用:向地址中加入 ? 或 &
'参 数:strUrl ----网址
'返回值:加了 ? 或 & 的网址
'**************************************************
function JoinChar(strUrl)
if strUrl="" then
JoinChar=""
exit function
end if
if InStr(strUrl,"?")<len(strUrl) then
if InStr(strUrl,"?")>1 then
if InStr(strUrl,"&")<len(strUrl) then
JoinChar=strUrl & "&"
else
JoinChar=strUrl
end if
else
JoinChar=strUrl & "?"
end if
else
JoinChar=strUrl
end if
end function

'**************************************************
'过程名:showpage
'作 用:显示“上一页 下一页”等信息
'参 数:sfilename ----链接地址
' totalnumber ----总数量
' maxperpage ----每页数量
' ShowTotal ----是否显示总数量
' ShowAllPages ---是否用下拉列表显示所有页面以供跳转。有某些页面不能使用,否则会出现JS错误。
' strUnit ----计数单位
'**************************************************
sub showpage(sfilename,totalnumber,maxperpage,ShowTotal,ShowAllPages,strUnit)
dim n, i,strTemp,strUrl
if totalnumber mod maxperpage=0 then
n= totalnumber \ maxperpage
else
n= totalnumber \ maxperpage+1
end if
strTemp= "<table width='100%'><tr><td align='center' height=25>"
if ShowTotal=true then
strTemp=strTemp & "共 <b>" & totalnumber & "</b> " & strUnit & "&nbsp;&nbsp;"
end if
strUrl=JoinChar(sfilename)
if page<2 then
strTemp=strTemp & "首页 上一页&nbsp;"
else
strTemp=strTemp & "<a href='" & strUrl & "page=1'>首页</a>&nbsp;"
strTemp=strTemp & "<a href='" & strUrl & "page=" & (Page-1) & "'>上一页</a>&nbsp;"
end if

if n-page<1 then
strTemp=strTemp & "下一页 尾页"
else
strTemp=strTemp & "<a href='" & strUrl & "page=" & (Page+1) & "'>下一页</a>&nbsp;"
strTemp=strTemp & "<a href='" & strUrl & "page=" & n & "'>尾页</a>"
end if
strTemp=strTemp & "&nbsp;页次:<strong><font color=red>" & Page & "</font>/" & n & "</strong>页 "
strTemp=strTemp & "&nbsp;<b>" & maxperpage & "</b>" & strUnit & "/页"
if ShowAllPages=True then
strTemp=strTemp & "&nbsp;转到:<select name='page' size='1' onchange=""javascript:window.location='" & strUrl & "page=" & "'+this.options[this.selectedIndex].value;"">"
for i = 1 to n
strTemp=strTemp & "<option value='" & i & "'"
if cint(Page)=cint(i) then strTemp=strTemp & " selected "
strTemp=strTemp & ">第" & i & "页</option>"
next
strTemp=strTemp & "</select>"
end if
strTemp=strTemp & "</td></tr></table>"
response.write strTemp
end sub
%>
2006-12-05 08:55
tang688
Rank: 5Rank: 5
等 级:贵宾
威 望:16
帖 子:1219
专家分:35
注 册:2004-12-25
收藏
得分:0 
JoinChar(sfilename)这个值是什么啊?把它打印出来看看

2006-12-05 09:06
ak168
Rank: 1
等 级:新手上路
帖 子:3
专家分:0
注 册:2006-12-5
收藏
得分:0 
我也不懂,求助朋友们帮忙啊
2006-12-05 09:14
快速回复:asp查询分页浏览代码的错误在哪?
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.027370 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved