SitePoint Sponsor

User Tag List

Results 1 to 6 of 6

Thread: Can I do this?

  1. #1
    SitePoint Addict thachp's Avatar
    Join Date
    Aug 2004
    Location
    Seattle
    Posts
    222
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Can I do this?

    Can I do this? If not got altenate idea? I have a table with two columns. ftr_sampler is set as varchar(255). I want the script to search for similar keyword in the ftr_sampler.

    sample table:
    id ftr_sampler
    - -----------
    1 I like to eat apple.


    Code:
    <% if RS3("ftr_sampler") = "%apple%" Then %>
    Id 1 like to eat apple.
    <% else %>
    Id 1 does not like to eat apple.
    <% end if %>

  2. #2
    SitePoint Member
    Join Date
    Jun 2006
    Posts
    7
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    str = "Id 1 does not like to eat apple."
    if instr(RS3("ftr_sampler"),"&#37;apple%") > 0 Then str = "Id 1 like to eat apple."
    response.write str

  3. #3
    SitePoint Member
    Join Date
    Jun 2006
    Posts
    7
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    probably more efficient would be


    if instr(RS3("ftr_sampler"),"&#37;apple%") > 0 Then response.write "Id 1 like to eat apple." else response.write "Id 1 does not like to eat apple."

  4. #4
    SitePoint Addict
    Join Date
    Dec 2002
    Location
    Gent, Belgium, Europe, World, Univers
    Posts
    397
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I believe you should drop the "&#37;" signs when doing an instr() function.

    the % is used directly in your Query with a LIKE clause ...

  5. #5
    SitePoint Enthusiast
    Join Date
    Jul 2006
    Location
    South Dakota
    Posts
    77
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Why not choose the ID's that like to eat apples and all others don't

    Code:
    set conn = CreateObject("ADODB.Connection")
    conn.open "connection string"
    set RS3 = conn.Execute("SELECT id FROM table_name WHERE ftr_sampler LIKE '%apple%'")
     
    do while RS3.EOF
        "Id " & RS3("id") & "likes to eat apples" & vbcrlf
    loop
    This is certainly a better way to get what you want from the DB. Otherwise use instr as otherwise noted.
    TDDJournal: An Experiment in Test Driven Development.

  6. #6
    Original Gangster silver trophy Thing's Avatar
    Join Date
    Oct 2000
    Location
    Philadelphia, PA
    Posts
    4,708
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by kajakske View Post
    I believe you should drop the "%" signs when doing an instr() function.

    the % is used directly in your Query with a LIKE clause ...

    That's correct.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •