The first thing you need to do is create a database called MyDatabase. Then create a table called tblFAQ with these fields:
ID - autonumber
Question - text field
Answer - text field
DateEntered - date/time field
Then, start adding some questions and answers to your database.
Next, create a page called searchengine.asp and copy the below code into your page:
<% DIM strSearchterm strSearchterm = Request.Form("searchterm") IF strSearchterm <> "" THEN
DIM mySQL, objRS
mySQL = "SELECT * FROM tblFAQ WHERE (Question LIKE '%" & strSearchterm & "%') OR (Answer LIKE '%" & strSearchterm & "%')"
Set objRS = Server.CreateObject("ADODB.Recordset")
objRS.Open mySQL, objConn, adOpenKeyset, adLockPessimistic, adCmdText
IF objRS.EOF THEN
Response.Write "Sorry, no records were found for that searchterm"
ELSE
%>
Question | Answer |
<%=objRS("Question")%> | <%=objRS("Answer")%> |
<% ELSE ' No searchterm submitted, display blank END IF %>
This script will display your search form each time the page is accessed. When a search term is submitted, it will search both the question and answer fields in your database for any data that contains the search term. There you have it. Your first albeit simple search engine.
http://www.aspwebpro.com/aspscripts/websitetools/searchengine.asp
No comments:
Post a Comment