Hi,everybody. I have question in using ajax and do the split the long text in database(Access). Below is a database that in my database: And I would like to split the keyword based on the "," And my code is like below: <% response.expires=0 Dim rsWords Dim rsWords_numRows Dim q q=Lcase(request.querystring("q")) Set rsWords = Server.CreateObject("ADODB.Recordset") rsWords.ActiveConnection = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Server.MapPath("db_hint_words.mdb") rsWords.Source = "SELECT * FROM TBL_WORDS WHERE word LIKE '% " + q + "%'" rsWords.CursorType = 0 rsWords.CursorLocation = 2 rsWords.LockType = 3 rsWords.Open() rsWords_numRows = 0 Dim My_String Dim My_Array My_String=rsWords("word") My_Array=split(My_String,",") For Each item In My_Array Response.Write("<br>" & item) Next rsWords.Close() Set rsWords = Nothing %> But it juz show the result And I do not know where is my mistake of it...Sigh... Hope have someone can guild me on it. Thanks.
For the next question by using the code on the top. It was give me the result similar like this... The user when select the word it will select all of it. And the display of the first row that is freeware, shareware was can't see get when the user key in the "f" at the form.
Your only retrieving the first record from the database... maybe try: (changes are indicated in red) response.expires=0 Dim rsWords Dim rsWords_numRows Dim q q=Lcase(request.querystring("q")) Set rsWords = Server.CreateObject("ADODB.Recordset") rsWords.ActiveConnection = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Server.MapPath("db_hint_words.mdb") rsWords.Source = "SELECT * FROM TBL_WORDS WHERE word LIKE '% " + q + "%'" rsWords.CursorType = 0 rsWords.CursorLocation = 2 rsWords.LockType = 3 rsWords.Open() rsWords_numRows = 0 Dim My_String Dim My_Array [COLOR="Red"]Do While Not rsWords.Eof[/COLOR] My_String=rsWords("word") My_Array=split(My_String,",") For Each item In My_Array Response.Write("<br>" & item) Next [COLOR="red"]rsWords.moveNext() Loop[/COLOR] rsWords.Close() Set rsWords = Nothing Code (markup):
Hi,i had apply on your code into my code and i had apply the new code to the code so my code become like this <%@LANGUAGE="VBSCRIPT" CODEPAGE="65001"%> <% response.expires=0 Dim rsWords Dim rsWords_numRows Dim q q=Lcase(request.querystring("q")) Set rsWords = Server.CreateObject("ADODB.Recordset") rsWords.ActiveConnection = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Server.MapPath("db_hint_words.mdb") rsWords.Source = "SELECT * FROM TBL_WORDS WHERE word LIKE '%" + q + "%'" rsWords.CursorType = 0 rsWords.CursorLocation = 2 rsWords.LockType = 3 rsWords.Open() rsWords_numRows = 0 Dim My_String Dim My_Array Do While Not rsWords.Eof My_String=rsWords("word") My_Array=split(My_String,",") For n=0 to ubound(My_Array) Response.write(My_Array(n))& vbCrLf Next rsWords.moveNext() Loop rsWords.Close() Set rsWords = Nothing %> then the first page the selection part was solve which apply & vbCrLf But for my second problem when i key in the alphabet "f", it still give me the output like below The correct output just list when i key in "fr" My problem is the unrelated output also have show in the list of the selection. And I still can't finding get the solution for this problem...>.< Thanks a lot for helping me...Thanks...
This could be a problem that is occurring on the javascript side of the script. Have you tried just writing the value of QueryString("q") to the screen... and see if the value is being sent when only one letter is typed??? I am assuming that you are using AJAX to load the list. Could you possibly post the rest of the page? If you want to do it this way you will need to also filter the input on the server-side to prevent errors and sql injection.
Ok,I will try about that... & I found get new problem the array was give me the same output although I use distinct at mysql cause the problem is I suppose to ignore the duplicate string at array. do you have any idea about that? Thanks...
I don't know why I missed this before but the problem is that you have multiple keywords within each field so you cannot use the SQL 'WHERE' condition to select the correct field. When you type in 'f' it is selecting all fields that contain 'f' and displaying all keywords from that field. You need to use a string function like 'InStr', after splitting the data, and check each keyword individually. Something like: <%@LANGUAGE="VBSCRIPT" CODEPAGE="65001"%> <% response.expires=0 Dim rsWords Dim rsWords_numRows Dim q q=Lcase(request.querystring("q")) Set rsWords = Server.CreateObject("ADODB.Recordset") rsWords.ActiveConnection = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Server.MapPath("db_hint_words.mdb") rsWords.Source = "SELECT * FROM TBL_WORDS WHERE word LIKE '%" + q + "%'" rsWords.CursorType = 0 rsWords.CursorLocation = 2 rsWords.LockType = 3 rsWords.Open() rsWords_numRows = 0 Dim My_String Dim My_Array Do While Not rsWords.Eof My_String=rsWords("word") My_Array=split(My_String,",") For n=0 to ubound(My_Array) [COLOR="Red"]If InStr(My_Array(n),q) Then Response.write(My_Array(n))& vbCrLf End If[/COLOR] Next rsWords.moveNext() Loop rsWords.Close() Set rsWords = Nothing %> Code (markup):
You could also now change the SQL line to: rsWords.Source = "SELECT * FROM TBL_WORDS" Code (markup): Which will save you from errors and SQL injection... although this code may run slower (unnoticeably, unless the database is a reasonable size)... it's the way it has to be unless you change your database setup.