1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

Problem in doing split the asp data

Discussion in 'C#' started by squall2463, Aug 20, 2009.

  1. #1
    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:
    [​IMG]


    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

    [​IMG]

    :(

    And I do not know where is my mistake of it...Sigh...

    Hope have someone can guild me on it.

    Thanks.
     
    Last edited: Aug 20, 2009
    squall2463, Aug 20, 2009 IP
  2. squall2463

    squall2463 Peon

    Messages:
    7
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    For the next question by using the code on the top. It was give me the result similar like this...
    [​IMG]

    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.
     
    squall2463, Aug 20, 2009 IP
  3. camjohnson95

    camjohnson95 Active Member

    Messages:
    737
    Likes Received:
    17
    Best Answers:
    0
    Trophy Points:
    60
    #3
    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):
     
    camjohnson95, Aug 21, 2009 IP
  4. camjohnson95

    camjohnson95 Active Member

    Messages:
    737
    Likes Received:
    17
    Best Answers:
    0
    Trophy Points:
    60
    #4
    maybe try explaining the second problem again....
     
    camjohnson95, Aug 21, 2009 IP
  5. squall2463

    squall2463 Peon

    Messages:
    7
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    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

    [​IMG]

    The correct output just list when i key in "fr"

    [​IMG]

    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...:)
     
    squall2463, Aug 23, 2009 IP
  6. camjohnson95

    camjohnson95 Active Member

    Messages:
    737
    Likes Received:
    17
    Best Answers:
    0
    Trophy Points:
    60
    #6
    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.
     
    camjohnson95, Aug 23, 2009 IP
  7. squall2463

    squall2463 Peon

    Messages:
    7
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #7
    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...:)
     
    squall2463, Aug 24, 2009 IP
  8. camjohnson95

    camjohnson95 Active Member

    Messages:
    737
    Likes Received:
    17
    Best Answers:
    0
    Trophy Points:
    60
    #8
    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):
     
    camjohnson95, Aug 24, 2009 IP
  9. camjohnson95

    camjohnson95 Active Member

    Messages:
    737
    Likes Received:
    17
    Best Answers:
    0
    Trophy Points:
    60
    #9
    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.
     
    camjohnson95, Aug 24, 2009 IP