主题:  这个常见的搜索是怎样做的?

wanlixwl

职务:普通成员
等级:1
金币:0.0
发贴:113
注册:2002/11/14 9:37:03
#12003/1/18 8:56:05
各大网站都有,输入关键字后,可以选是按类别查询,比如按“作者”按“标题””日期“等等,这样总共要做几个搜索页面?是一个类别一个搜索页面么?如果是这样的话,那表单的action怎么做呢?需不需要用到表单,我只会做单个的搜索!



98tj

职务:普通成员
等级:1
金币:0.0
发贴:28
注册:2003/1/7 8:22:14

wanlixwl

职务:普通成员
等级:1
金币:0.0
发贴:113
注册:2002/11/14 9:37:03
#32003/1/18 10:26:45
那上面那么长一段代码,太麻烦了,我想直接在dwmx中就应该做得到的吧?能不能详细一点?
再次感谢你!!!



肖天

职务:普通成员
等级:1
金币:0.0
发贴:37
注册:2002/8/12 1:18:27
#42003/1/18 11:17:09
只用做一个结果页面result.asp即可
在search.asp页面中加入一个下拉菜单

然后再加一个文本框

当然少不了一个submit按钮
记住设置


在result.asp中
新建记录集rsresult
切换到advanced视图
新增两个参数:
MMColParam | theauthor | Request.QueryString("feild")
MMColParam2 | % | Request.QueryString("keyword")

SQL中设置:
SELECT *
FROM tabalname
WHERE MMColParam LIKE '%MMColParam2%'

一切OK,我在IIS 5 +ASP+SQL Server中测试过,一点问题没有,在Access下应该不会有问题。



编辑历史:[这消息被肖天编辑过(编辑时间2003-01-18 11:17:35)]


98tj

职务:普通成员
等级:1
金币:0.0
发贴:28
注册:2003/1/7 8:22:14
#52003/1/18 12:06:47
wanlixwl在上个帖子中说
引用:
那上面那么长一段代码,太麻烦了,我想直接在dwmx中就应该做得到的吧?能不能详细一点?
再次感谢你!!!


不行的,必须用手写加一个判断,才行呀

搜索页,我不用说了,很简单

在结果页里, <% if (Request.QueryString("sele") = "q_name") then
是判断下拉菜单里传递过来的参数是不是Q_NAME, 如果则运下,下面的代码

<% if (Request.QueryString("sele") = "q_ADD") then
是判断下拉菜单里传递过来的参数是不是Q_ADD, 如果则运下,下面的代码
现在清楚了吧



wanlixwl

职务:普通成员
等级:1
金币:0.0
发贴:113
注册:2002/11/14 9:37:03
#62003/1/19 11:21:44
我用肖天的方法试了好长时间都不行,另外你的这段代码我也不懂,在result.asp中
新增两个参数:
MMColParam | theauthor | Request.QueryString("feild")
MMColParam2 | % | Request.QueryString("keyword")

SQL中设置:
SELECT *
FROM tabalname
WHERE MMColParam LIKE '%MMColParam2%'
测试的时候总是说”至少有一个参数未设定“
默认值为什么会是“theauthou"和”%“



98tj

职务:普通成员
等级:1
金币:0.0
发贴:28
注册:2003/1/7 8:22:14
#72003/1/19 13:05:27
你搞错了吧,我再把代码重贴一次吧
search.asp
_________________________________________________


Untitled Document












客户查询系统














查询类别:



关 键 字:












_____________________________________________
searchok.asp
______________________________________________
<%@LANGUAGE="VBSCRIPT"%>

<%
Dim list__MMColParam
list__MMColParam = "%"
if (Request.QueryString("keyword") <> "") then list__MMColParam = Request.QueryString("keyword")
%>
<% if (Request.QueryString("sele") = "q_name") then
set list = Server.CreateObject("ADODB.Recordset")
list.ActiveConnection = MM_conn_STRING
list.Source = "SELECT * FROM mumtable WHERE q_name LIKE '%" + Replace(list__MMColParam, "'", "''") + "%' ORDER BY id DESC"
list.CursorType = 0
list.CursorLocation = 2
list.LockType = 3
list.Open()
list_numRows = 0
end if
%>
<% if (Request.QueryString("sele") = "q_add") then
set list = Server.CreateObject("ADODB.Recordset")
list.ActiveConnection = MM_conn_STRING
list.Source = "SELECT * FROM mumtable WHERE q_add LIKE '%" + Replace(list__MMColParam, "'", "''") + "%' ORDER BY id DESC"
list.CursorType = 0
list.CursorLocation = 2
list.LockType = 3
list.Open()
list_numRows = 0
end if
%>
<%
Dim Repeat1__numRows
Repeat1__numRows = -1
Dim Repeat1__index
Repeat1__index = 0
list_numRows = list_numRows + Repeat1__numRows
%>
<%
' *** Recordset Stats, Move To Record, and Go To Record: declare stats variables

' set the record count
list_total = list.RecordCount

' set the number of rows displayed on this page
If (list_numRows < 0) Then
list_numRows = list_total
Elseif (list_numRows = 0) Then
list_numRows = 1
End If

' set the first and last displayed record
list_first = 1
list_last = list_first + list_numRows - 1

' if we have the correct record count, check the other stats
If (list_total <> -1) Then
If (list_first > list_total) Then list_first = list_total
If (list_last > list_total) Then list_last = list_total
If (list_numRows > list_total) Then list_numRows = list_total
End If
%>
<%
' *** Recordset Stats: if we don't know the record count, manually count them

If (list_total = -1) Then

' count the total records by iterating through the recordset
list_total=0
While (Not list.EOF)
list_total = list_total + 1
list.MoveNext
Wend

' reset the cursor to the beginning
If (list.CursorType > 0) Then
list.MoveFirst
Else
list.Requery
End If

' set the number of rows displayed on this page
If (list_numRows < 0 Or list_numRows > list_total) Then
list_numRows = list_total
End If

' set the first and last displayed record
list_first = 1
list_last = list_first + list_numRows - 1
If (list_first > list_total) Then list_first = list_total
If (list_last > list_total) Then list_last = list_total

End If
%>


Untitled Document











<%
While ((Repeat1__numRows <> 0) AND (NOT list.EOF))
%>







<%
Repeat1__index=Repeat1__index+1
Repeat1__numRows=Repeat1__numRows-1
list.MoveNext()
Wend
%>
         
<%=(list.Fields.Item("id").value)%> <%=(list.Fields.Item("q_name").value)%> <%=(list.Fields.Item("q_add").value)%> <%=(list.Fields.Item("q_data").value)%> <%=(list.Fields.Item("q_dengji").value)%>



<%
list.Close()
%>



wanlixwl

职务:普通成员
等级:1
金币:0.0
发贴:113
注册:2002/11/14 9:37:03
#82003/1/19 15:48:02
好了,我解决了!!!非常感谢两位!!!!我用的是肖天的方法,用两个变量解决问题:
MMColParam Request.QueryString("feild")
MMColParam2 | Request.QueryString("keyword")
第一个变量代表的是下拉菜单(也就是类别)的值,第二个代表的是文本框值,然后用一个WHERE MMColParam LIKE '%MMColParam2%'语句让asp去查询!我原来不成功的原因是,下拉菜单的变量不是数据库中的字段名,这个一定要一致!!!是吧!
再次感谢两位!!!!

听君一席话,胜读十年书,以后再多请教!!!!