一个关于搜索的问题~ 搜索栏有5个项目,不填关键字直接搜索其中的任意一个,在不超过一页的时候没有问题,超过一页会出现如下的问题,第一页显示正确,但点下页到第二页时会发现把数据库里所有的东西都调出来了,而不是搜索到的东西了,请高手指教~~ 搜索框的代码: <table width="100%" border="0" cellpadding="0" cellspacing="0"> <form name="FindForm" method="post" action="FindBody.asp"> <tr bgcolor="#FFFFFF"> <td> </td> <td> </td> </tr> <tr bgcolor="#FFFFFF"> <td height="24" align="right">类 别:</td> <td><select name="Sort" class="Button" id="Sort"> <option value="" selected>=请选择=</option> <% Set FRs=Server.CreateObject ("ADODB.Recordset") FindSQL="Select * From Class Order by Class_Num" FRs.Open FindSQL,Dbconn,1,1 Do Until FRs.EOF %> <option value="<%=FRs("CID")%>"><%=FRs("Class_Name")%></option> <% FRs.MoveNext Loop FRs.Close Set FRs=Nothing %> </select></td> </tr> <tr bgcolor="#FFFFFF"> <td height="24" align="right">关键字:</td> <td><INPUT id=KeyWord size=12 name=KeyWord></td> </tr> <tr align="center" bgcolor="#FFFFFF"> <td height="24" colspan="2"><INPUT class=Button id=Find onclick="FindForm.submit()" type=button value="搜 索" name=Find> <INPUT class=Button id=Reset type=reset value="重 置" name=Reset></td> </tr> <tr bgcolor="#FFFFFF"> <td> </td> <td> </td> </tr> </form> </table> FindBody.asp的代码: <%
Const MaxPerPage=9 Dim TotalPut Dim CurrentPage Dim TotalPages Dim CID Dim KeyWord
If Not isempty(Request("Page")) Then CurrentPage=Cint(Request("Page")) Else CurrentPage=1 End if
CID=Request("Sort") KeyWord =Request("KeyWord")
Set Rs=Server.CreateObject ("ADODB.Recordset")
If CID<>"" Then StrSQL="SELECT * FROM Image Where CID="& CID &" and Model like '%" & KeyWord &"%' ORDER BY ID DESC" Else
StrSQL="SELECT * FROM Image ORDER BY ID DESC" End If Rs.Open StrSQL,dbconn,1,1
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 %>
<% Set Ds=Server.CreateObject ("ADODB.Recordset") DsSQL="Select * From Class Order By Class_Num" Ds.Open DsSQL,DbConn,1,1 Do Until Ds.EOF %> <td height="30"><a href="Product.asp?CID=<%=Ds("CID")%>"><%=Ds("Class_Name")%></a></td> <% Ds.MoveNext Loop Ds.Close Set Ds=Nothing %>
<% If CurrentPage=1 Then ShowContent Showpage Totalput,MaxPerPage,"FindBody.asp" Else If (CurrentPage-1)*MaxPerPage<TotalPut Then Rs.move (CurrentPage-1)*MaxPerPage Dim bookmark bookmark=rs.bookmark ShowContent Showpage Totalput,MaxPerPage,"FindBody.asp" Else CurrentPage=1 ShowContent Showpage Totalput,MaxPerPage,"FindBody.asp" End If End If Sub ShowContent Do While Not Rs.EOF '第一格
Response.Write "<tr align='center'>" Response.Write "<td width='33%'>" Response.Write "<table width=160 height=140 border=0 cellpadding=0 cellspacing=1 bgcolor=#CCCCCC><tr>" Response.Write "<td align=center bgcolor=#FFFFFF><img src='Photo/"& Rs("S_Image") &"' onclick=iPop('Photo/"& Rs("D_Image") &"',"& Rs("Width") &","& Rs("Height") &",'平湖市卓树塑料五金厂') style='CURSOR:hand' width=150 height=130></td></tr></table>" Response.Write "<table width=160 border=0 cellspacing=0 cellpadding=0><tr>" Response.Write "<td height=40 align=center>"& Rs("Model") &"</td></tr></table></td>"
i=i+1 If i>=MaxPerPage Then Exit Do rs.MoveNext If Rs.EOF Then
Response.Write "<td width='33%'>" Response.Write "</td>"
Response.Write "<td width='33%'>" Response.Write "</td>" Response.Write "</tr>" Exit Do
End If
'第二格 Response.Write "<td width='33%'>" Response.Write "<table width=160 height=140 border=0 cellpadding=0 cellspacing=1 bgcolor=#CCCCCC><tr>" Response.Write "<td align=center bgcolor=#FFFFFF><img src='Photo/"& Rs("S_Image") &"' onclick=iPop('Photo/"& Rs("D_Image") &"',"& Rs("Width") &","& Rs("Height") &",'平湖市卓树塑料五金厂') style='CURSOR:hand' width=150 height=130></td></tr></table>" Response.Write "<table width=160 border=0 cellspacing=0 cellpadding=0><tr>" Response.Write "<td height=40 align=center>"& Rs("Model") &"</td></tr></table></td>" i=i+1 If i>=MaxPerPage Then Exit Do rs.MoveNext If Rs.EOF Then
Response.Write "<td width='33%'>" Response.Write "</td>" Response.Write "</tr>" Exit Do
End If
'第三格 Response.Write "<td width='33%'>" Response.Write "<table width=160 height=140 border=0 cellpadding=0 cellspacing=1 bgcolor=#CCCCCC><tr>" Response.Write "<td align=center bgcolor=#FFFFFF><img src='Photo/"& Rs("S_Image") &"' onclick=iPop('Photo/"& Rs("D_Image") &"',"& Rs("Width") &","& Rs("Height") &",'平湖市卓树塑料五金厂') style='CURSOR:hand' width=150 height=130></td></tr></table>" Response.Write "<table width=160 border=0 cellspacing=0 cellpadding=0><tr>" Response.Write "<td height=40 align=center>"& Rs("Model") &"</td></tr></table></td></tr>"
i=i+1 If i>=MaxPerPage Then Exit Do rs.movenext Loop 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
%> </table> <table width="100%" border="0" cellspacing="0" cellpadding="0"> <tr> <td height="30" align="right"><% response.write "<font color=#000000'> 共 <b>"&totalnumber&"</b> 条记录 <b>"&maxperpage&"</b> 条记录/每页</font> " If CurrentPage<2 Then response.write "<font color='#b9b9b9'>首页 上一页</font> " Else response.write "<a href="&Filename&"?Sort="&Sort&"&KeyWord="& KeyWord &"&Page=1 class=green>首页</a> " response.write "<a href="&Filename&"?Sort="&Sort&"&KeyWord="& KeyWord &"&Page="&CurrentPage-1&" class=green>上一页</a> " End If If n-currentpage<1 Then response.write "<font color='#b9b9b9'>下一页 尾页</font>" Else response.write "<a href="&Filename&"?Sort="&Sort&"&KeyWord="& KeyWord &"&Page="&(CurrentPage+1)&" class=green>下一页</a> " response.write "<a href="&Filename&"?Sort="&Sort&"&KeyWord="& KeyWord &"&Page="&n&" class=green>尾页 </a>" End If response.write "<font color=#000000> 当前第 <b>"& Currentpage &"</b> 页</font> " End Function %> 请高手指点,万分感谢~~~