菜鸟提问:关于查询分页问题!!!

tangss 2004-01-10 10:32:57
我怎样控制在查询字符串为空时不查出内容呢?SQL语句必须用LIKE。
请大家帮忙看一下!谢了先!
<%
dim conn
dim connstr
dim db
dim rescount
db="ckdb.mdb" '数据库文件的位置
Set conn = Server.CreateObject("ADODB.Connection")
connstr="driver={Microsoft Access Driver (*.mdb)};dbq=" & Server.MapPath(db)
conn.Open connstr
Set rs = Server.CreateObject("ADODB.Recordset")

'rs.open "select * from tbl_ckstock ",conn,1,1
'rescount= rs.fields.count -1
%>
<%
const MaxPerPage=15
dim totalPut
dim CurrentPage
dim TotalPages
dim i,j
dim sql
dim rs
dim rstype
dim typesql


if not isempty(request("page")) then
currentPage=cint(request("page"))
else
currentPage=1
end if
%>

<%
dim findtype
findtype=request.form("searchetype")

sql="select * from tbl_ckstock where col_producttype like '"&findtype&"%'"

IF trim(findtype)="" then '加了这段翻页功能就失效,不加的话当查询字符串为空时仍能查出,
response.end '而我要求查询字符串不能为空
end if '

Set rs= Server.CreateObject("ADODB.Recordset")
rs.open sql,conn,1
if rs.eof and rs.bof then
response.write "<p align='center'> 抱歉没有找到您要查找的型号!</p>"
else
totalPut=rs.recordcount
totalPut=rs.recordcount
if currentpage<1 then
currentpage=1
end if
if (currentpage-1)*MaxPerPage>totalput then
if (totalPut mod MaxPerPage)=0 then
currentpage= totalPut \ MaxPerPage
else
currentpage= totalPut \ MaxPerPage + 1
end if

end if
if currentPage=1 then
showContent
showpage totalput,MaxPerPage,"query.asp"
else
if (currentPage-1)*MaxPerPage<totalPut then
rs.move (currentPage-1)*MaxPerPage
dim bookmark
bookmark=rs.bookmark
showContent
showpage totalput,MaxPerPage,"query.asp"
else
currentPage=1
showContent
showpage totalput,MaxPerPage,"query.asp"
end if
end if
rs.close
end if

set rs=nothing
conn.close
set conn=nothing

sub showContent
dim i
i=0

%>
<table border="0" cellpadding="0" cellspacing="1" style="border-collapse: collapse" bordercolor="#111111"width="98%" id="AutoNumber1" align="center" bgcolor="#00CCFF" >
<tr bgcolor="#0066CC">
<td align=middle bgcolor="#0066CC" height="22"width="6%">  </td>
<td type= "hidden" style="display:none"width="10%" align="center" height="22" bgcolor="#0066CC"> <font color="#FFFFFF">
序 号</font></td>
<td width="23%" align="center" height="22" bgcolor="#0066CC"> <font color="#FFFFFF">
型 号</font></td>
<td width="8%" align="center" height="22"> <font color="#FFFFFF">厂 家</font></td>

<td width="12%" align="center" height="22"><font color="#FFFFFF">修改</font></td>
<td width="13%" align="center" height="22"><font color="#FFFFFF">删除</font></td>
</tr>
<%do while not rs.eof%>
<tr bgcolor="eeeeee">
<td align=middle>
<input name=product_id type=checkbox
value=<%=rs("col_StockProductId")%>>
</td>
<td type="hidden" style="display:none" width="10%" align="center" height="18"><%=rs("col_StockProductId")%></td>
<td width="23%" align="center" height="18"><%=rs("col_producttype")%></td>
<td width="8%" align="center" height="18"><%=rs("col_ProductFactory")%></td>

<td width="12%" align="center" height="18"><a href="editnews.asp?newsid=<%=rs("col_producttype")%>&page=<%=CurrentPage%>" >修改</a></td>
<td width="13%" align="center" height="18"><a href="delenews.asp?newsid=<%=rs("col_producttype")%>&page=<%=CurrentPage%>">删除</a></td>
</tr>
<% i=i+1
if i>=MaxPerPage then exit do
rs.movenext
loop
%>
</table>
<%
end sub

function showpage(totalnumber,maxperpage,filename)
dim n
if totalnumber mod maxperpage=0 then
n= totalnumber \ maxperpage
else
n= totalnumber \ maxperpage+1
end if
response.write "<form method=Post action="&filename&">"

response.write "<p align='center'> "
if CurrentPage<2 then
response.write "<font color='#000080'>首页 上一页</font> "
else
response.write "<a href="&filename&"?page=1>首页</a> "
response.write "<a href="&filename&"?page="¤tPage-1&">上一页</a> "
end if
if n-currentpage<1 then
response.write "<font color='#000080'>下一页 尾页</font>"
else
response.write "<a href="&filename&"?page="&(CurrentPage+1)&">"
response.write "下一页</a> <a href="&filename&"?page="&n&">尾页</a>"
end if
response.write "<font color='#000080'> 页次:</font><strong><font color=red>"¤tPage&"</font><font color='#000080'>/"&n&"</strong>页</font> "
response.write "<font color='#000080'> 共<b>"&totalnumber&"</b>条记录 <b>"&maxperpage&"</b>条记录/页</font> "
response.write " <font color='#000080'>转到:</font><input type='text' name='page' size=2 maxlength=10 class=smallInput value="¤tpage&">"
response.write "<input type='hidden' value='提交' name='submit1'><input type='image' src='../images/go.gif' value='提交' name='submit1' ></span></p></form>"
end function
%>
...全文
65 29 打赏 收藏 转发到动态 举报
写回复
用AI写文章
29 条回复
切换为时间正序
请发表友善的回复…
发表回复
u1234 2004-05-06
  • 打赏
  • 举报
回复
能不能把修改好的东西贴出来.
hwkknd 2004-01-10
  • 打赏
  • 举报
回复
已发送,查收
在我这运行时JScript出错,因为我手里还有些事情,我没帮你调试…
为能使其在我机器上运行,asp文件内form action略做改动
如果到你处无法运行,请更改原样…
tangss 2004-01-10
  • 打赏
  • 举报
回复
先谢谢了,tangss3@vip.sina.com
hwkknd 2004-01-10
  • 打赏
  • 举报
回复
好,我去看看,留下EMAIL,我改了发给你
tangss 2004-01-10
  • 打赏
  • 举报
回复
里面我没有加

IF trim(findtype)="" then '加了这段翻页功能就失效,不加的话当查询字符串为空时仍能查出,
response.end '而我要求查询字符串不能为空
end if
tangss 2004-01-10
  • 打赏
  • 举报
回复
hwkknd(白开水) 你好,我已把query.asp 和ckdb.rar 传了过去
hwkknd 2004-01-10
  • 打赏
  • 举报
回复
上传好了告诉我一声
tangss 2004-01-10
  • 打赏
  • 举报
回复
我的是ACCESS,你的邮箱呢
pimple 2004-01-10
  • 打赏
  • 举报
回复
你的分页写的有问题..

不过不是自己写的程序,有好多东西看着也很迷茫.呵呵..
个人感觉你的分页写的麻烦了..
hwkknd 2004-01-10
  • 打赏
  • 举报
回复
没数据了大概两种原因,一是查询条件不符,这个你把SQL语句Write出来就可以知道了
再有就是Rs记录集没控制好,这个查看一下关于Rs运行时属性便可以,
你一句没数据了,我是摸不清头脑……
如果可以导成ACCESS数据库,压缩一下上传到
FTP://Hwkknd:Hwkknd@bestarit.8800.org
hwkknd 2004-01-10
  • 打赏
  • 举报
回复
你数据库是什么的?如果是ACCESS的发过来我帮你调试
aspnetxp 2004-01-10
  • 打赏
  • 举报
回复
不会,顶了...
tangss 2004-01-10
  • 打赏
  • 举报
回复
Tohwkknd(白开水) : 不是searchetype为空,而是一翻页就没数据了
tangss 2004-01-10
  • 打赏
  • 举报
回复
searchtype 的值传过来了,而且可以查到记录,但一翻页就没数据了。
hwkknd 2004-01-10
  • 打赏
  • 举报
回复
这次是什么问题?难道还会有searchetype为空?
xieyj 2004-01-10
  • 打赏
  • 举报
回复
你确认searchtype 的值传过来了,使用 request.querystring("searchtype")得不到值
tangss 2004-01-10
  • 打赏
  • 举报
回复
To hwkknd(白开水) :不行啊,我试了,还是一翻页就有问题
hwkknd 2004-01-10
  • 打赏
  • 举报
回复
不好意思,少了个等号
if CurrentPage<2 then
response.write "<font color='#000080'>首页 上一页</font> "
else
response.write "<a href="&filename&"?page=1&searchetype="&searchetype&">首页</a> "
response.write "<a href="&filename&"?page="¤tPage-1&"&searchetype="&searchetype&">上一页</a> "
end if
if n-currentpage<1 then
response.write "<font color='#000080'>下一页 尾页</font>"
else
response.write "<a href="&filename&"?page="&(CurrentPage+1)&"&searchetype="&searchetype&">"
response.write "下一页</a> <a href="&filename&"?page="&n&"&searchetype="&searchetype&">尾页</a>"
end if
hwkknd 2004-01-10
  • 打赏
  • 举报
回复
你的searchetype 第一次是以post方式传入的,当点击下一页的时候,searchetype已经不存在了当然为空,改成下面的样子试试
if CurrentPage<2 then
response.write "<font color='#000080'>首页 上一页</font> "
else
response.write "<a href="&filename&"?page=1&searchetype="&searchetype&">首页</a> "
response.write "<a href="&filename&"?page="¤tPage-1&"&searchetype="&searchetype&">上一页</a> "
end if
if n-currentpage<1 then
response.write "<font color='#000080'>下一页 尾页</font>"
else
response.write "<a href="&filename&"?page="&(CurrentPage+1)&"&searchetype"&searchetype&">"
response.write "下一页</a> <a href="&filename&"?page="&n&"&searchetype="&searchetype&">尾页</a>"
end if
tangss 2004-01-10
  • 打赏
  • 举报
回复
To ygghost(刘华强):那我要怎样做呢?
加载更多回复(9)

28,391

社区成员

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

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