菜鸟提问:关于查询分页问题!!!
我怎样控制在查询字符串为空时不查出内容呢?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
%>