如何使ASP實現(xiàn)搜索關鍵字高亮_ASP教程
教程Tag:暫無Tag,歡迎添加,賺取U幣!
推薦:解析ASP檢查網(wǎng)站鏈接是否正常的函數(shù)% FunctionurlChk(sUrl) onerrorresumenext SetxmlHttp=Server.CreateObject(Microsoft.XMLHTTP) xmlHttp.openGET,sUrl,false xmlHttp.send ifxmlHttp.Status200then urlChk=false else urlChk=true endif EndFunction sUrl=http://www.code-123.com ifu
用ASP實現(xiàn)搜索引擎的功能是一件很方便的事,可是,如何實現(xiàn)類似3721的智能搜索呢?比如,當在搜索條件框內(nèi)輸入“中國人民”時,自動從中提取“中國”、“人民”等關鍵字并在數(shù)據(jù)庫內(nèi)進行搜索�?赐瓯疚暮�,你就可以發(fā)現(xiàn),這個功能實現(xiàn)起來竟然是如此的簡單。第一步,我們要建立一個名為db_sample.mdb的數(shù)據(jù)庫(本文以Access2000數(shù)據(jù)庫為例),并在其中建立表T_Sample.表T_Sample包括如下字段:
ID 自動編號
U_Name 文本
U_Info 備注
第二步,我們開始設計搜索頁面Search.asp.該頁面包括一個表單(Frm_Search),表單內(nèi)包括一個文本框和一個提交按鈕。并將表單的method屬性設為“get” ,action屬性設為“Search.asp",即提交給網(wǎng)頁自身。代碼如下:
| <!-- Search.asp --> <form name="frm_Search" method="get" action="Search.asp"> 請輸入關鍵字: <input type="text" name="key" size="10"> <input type="submit" value="搜索"> </form> |
下面,就進入了實現(xiàn)智能搜索的關鍵部分。
首先,建立數(shù)據(jù)庫連接。在Search.asp的開始處加入如下代碼:
| <% Dim strProvider,CNN strProvider="Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" strProvider=strProvider & Server.MapPath("\") & "\data\db_Sample.mdb" ’假設數(shù)據(jù)庫存放在主頁根目錄下的data目錄下 Set CNN = Server.CreateObject("ADODB.connection") CNN.Open strProvider 打開數(shù)據(jù)庫連接 %> |
接下來,判斷 ASP頁所接收到的數(shù)據(jù),并在數(shù)據(jù)庫中進行搜索。
| <font color="#FF0000">未找到任何結(jié)果�。�!</font> <% Else %> |
搜索名稱為“<font color="#FF0000"><%= S_Key %></font>”的項,共找到 <font color="#FF0000"><%= RST.RecordCount %></font> 項:
| <% While Not RST.EOF 遍歷整個記錄集,顯示搜索到的信息并設置鏈接 %> <!-- 此處可設為你所需要的鏈接目標 --> <font style="font: 12pt 宋體"><a href="info.asp?ID=<%= RST("ID") %>" target="_blank"><%= RST("U_Name") %></a></font> <!-- 顯示部分詳細內(nèi)容 --> <font style="font: 9pt 宋體"><%= Left(RST("U_Info"),150) %></font><p> <% RST.MoveNext Wend RST.Close Set RST=Nothing End If End If %> |
分享:ASP教程之a(chǎn)sp制作常見flash新聞圖片輪換代碼這是一個正常的網(wǎng)頁文件 html head metahttp-equiv=Content-Typecontent=text/html;charset=gb2312/ title 新聞圖片輪換 /title /head body !--#Includefile=diaoyong.asp-- /body /html 任何網(wǎng)頁只要調(diào)用下面這個文件(diaoyong.asp)就可以了,所用f
相關ASP教程:
- 相關鏈接:
- 教程說明:
ASP教程-如何使ASP實現(xiàn)搜索關鍵字高亮
。