Jump to content

Help regarding search problem


dev

Recommended Posts

Someone help me please,I am trying to build a dictionary, which will convert English to my local language. Iam using access db which have a table(search) contains 5 fields namely: id; name; url; keywords and dis. I am able to perform the seach for *ANYWORD* successfully and there is what i am facing problem. This search can't do a specific search for a word, For example: i want to translate word - "welcome" so this codes give me exactly result i.e. translation to welcome word. but when i type word for *COME* it gives me a result of both WELCOME and COME and this is my problem. I want to make it specific search for specific words only :) .I hope i am able to explain my problem to you. Please help me.This is the codes

<!-------------- search.asp ----------------><html><head><title>Kokborok Dictionary</title><style type="text/css">body{font:normal 84% arial;margin:0 30px 0;color:#024477;}.v{font:normal 64% verdana;}</style></head><body><%Dim strURLDim cnnSearch  ' ADO connectionDim rstSearch  ' ADO recordsetDim strDBPathDim strSQL     ' The SQL Query we build on the flyDim strSearch  ' The text being looked forDim iPageCurrent ' The page we're currently onDim iPageCount   ' Number of pages of recordsDim iRecordCount ' Count of the records returnedDim I            ' Standard looping variableConst adOpenStatic = 3Const adLockReadOnly = 1Const adCmdText = &H0001Const PAGE_SIZE = 10 ' any numberstrURL = Request.ServerVariables("URL")strSearch = Request.QueryString("search")If Request.QueryString("page") = "" TheniPageCurrent = 1ElseiPageCurrent = CInt(Request.QueryString("page"))End IfIf strSearch <> "" ThenstrDBPath = Server.MapPath("../access_db/data_dir.mdb")Set cnnSearch = Server.CreateObject("ADODB.Connection")cnnSearch.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & strDBPath & ";"strSQL = "SELECT name, url, dis " _& "FROM search " _& "WHERE name LIKE '%" & Replace(strSearch, "'", "''") & "%' " _& "OR keywords LIKE '%" & Replace(strSearch, "'", "''") & "%' " _& "OR dis LIKE '%" & Replace(strSearch, "'", "''") & "%' " _& "ORDER BY id;"Set rstSearch = Server.CreateObject("ADODB.Recordset")rstSearch.PageSize  = PAGE_SIZErstSearch.CacheSize = PAGE_SIZErstSearch.Open strSQL, cnnSearch, adOpenStatic, adLockReadOnly, adCmdTextiRecordCount = rstSearch.RecordCountiPageCount   = rstSearch.PageCountIf iRecordCount = 0 Then%><p align="center"><span class="headinghome"><font color="#000080" face="Arial">No matches found for "<%=search%>"  Please search again.</font></span></p><%ElserstSearch.AbsolutePage = iPageCurrent%><table cellspacing=0 cellpadding=0 border=0 width="100%" style="border:1px solid #4f7ea2;"><tr style="background:url(img/hd.gif)" class=v><td width="60%" height=22 style="padding-left:10px;">Twipra Era: <!--#include file="../date/twipra-era.asp"--></td><td width="40%" style="padding-right:10px;" align=right>TwiPra | Contact us</td></tr><tr><td style="padding:10px;"><img src="img/icon.gif" alt="Kokborok dictionary" width=333 height=48></td><td></td></tr><tr><td colspan=2 align=center><div style="background:url(img/src.gif);border:1px solid #98aebf;width:500px;margin:6px 0 10px;"><form action="<%= strURL %>" method="get" style="margin:0px;"><table><tr><td style="height:51px;font-size:13pt;" width="25%"><b>Enter word: </b></td><td width="50%"><input type="text" name="search" value="<%= strSearch %>" style="width:100%;"></td><td width="25%"> <input type="submit" value="Search"></td></tr></table></form></div></td></tr><tr><td style="background:#4f7ea2;padding:4px 0 4px 10px;color:#fff;font-size:10pt;"><b>Search word: <u><%=strsearch%></u></b></td><td align=right style="background:#4f7ea2;padding:4px 10px 4px;color:#fff;font-size:10pt;"><b>Search result: <u><%=iRecordCount%> matches</u></b></td></tr></table><%Do While Not rstSearch.EOF And rstSearch.AbsolutePage = iPageCurrent%><center><div style="width:400px;padding:10px;border:1px solid #444;background:#f9f9f9;margin:10px;"><table width="100%"><tr style="font-size:90%"><td width="40%" valign=top align=right style="padding-right:10px;"><b><%=strsearch%> :</b></td><td valign=top><b><%= rstSearch.Fields("name").Value %></b></td></tr></table></div></center><div style="padding:10px;border:1px solid #444;background:#f9f9f9;"><%= rstSearch.Fields("dis").Value %></div><%rstSearch.MoveNextLoopend ifend if%></body></html>

Edited by aspnetguy
Link to comment
Share on other sites

Hi,This will happen when you use LIKE in the SQL statement, if you are sure that the word will be in the database then there is no need to use LIKE instead directly look for the english word in the DB using "=" in your query.SELECT name, url, dis " _& "FROM search " _& "WHERE name = '" & Replace(strSearch, "'", "''") & "' " _& "OR keywords = '" & Replace(strSearch, "'", "''") & "' " _& "OR dis = '" & Replace(strSearch, "'", "''") & "' " _& "ORDER BY id;"HTH

Link to comment
Share on other sites

Thank you so much pulpfictionI did exactly what you have suggested and it work perfact. Thank you. It was my headach and you cured me instently.Thank you :) dev

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...