PHP Search Engine

Discussion in 'PHP' started by MisterSeller, Nov 1, 2009.

  1. #1
    I've been trying to make a search engine that will look for an already defined word, but the search engine comes up with different result even if i type the exact word.

    For example, if i type in: "James", the results will show up everything that begins with "Ja" or any other letter from the name "James".

    If i type in "James", i want the results to show me "James" only, and nothing else. The names will be pre-defined.

    I use something like this:
    "WHERE name LIKE '%$name%'"
    Code (markup):
    , but this shows up multiple results, instead of one exact result OR multiple exact results.

    Any help?
     
    MisterSeller, Nov 1, 2009 IP
  2. Sky AK47

    Sky AK47 Member

    Messages:
    298
    Likes Received:
    8
    Best Answers:
    1
    Trophy Points:
    45
    #2
    "WHERE name LIKE '$name'"
    Code (markup):
    Use that, % is like (.*) in regexp.
     
    Sky AK47, Nov 1, 2009 IP
  3. MisterSeller

    MisterSeller Peon

    Messages:
    35
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Thanks, but i've just tried and it doesn't show any results even though i've written the exact word.
    I'll look again to see if i'm doing something wrong.
     
    MisterSeller, Nov 1, 2009 IP
  4. jazzcho

    jazzcho Peon

    Messages:
    326
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    0
    #4
    omg

    Use Where name = '$name'

    Why the fu3K did you use LIKE when you need = ?
     
    jazzcho, Nov 1, 2009 IP
  5. MisterSeller

    MisterSeller Peon

    Messages:
    35
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    Because it's my first week using PHP and Mysql?

    edit:didn't work, by the way...
     
    MisterSeller, Nov 1, 2009 IP
  6. jazzcho

    jazzcho Peon

    Messages:
    326
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    0
    #6
    You have errors in other places too then... :D
     
    jazzcho, Nov 1, 2009 IP
  7. MisterSeller

    MisterSeller Peon

    Messages:
    35
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #7
    Probably...damn this is really frustrating.

    How long did it took you guys to get to that point where you could easily code something using PHP by just searching on the internet?
     
    MisterSeller, Nov 1, 2009 IP
  8. szalinski

    szalinski Peon

    Messages:
    341
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    0
    #8
    years. nobody said it was going to be easy, lol. actually, make that never. it's never easy...always have to use our heads and keep trying.

    just make sure you're not mixing up letter cases...i think WHERE name = 'James' is not the same as WHERE name = 'james'... :confused:
     
    szalinski, Nov 1, 2009 IP
  9. Sky AK47

    Sky AK47 Member

    Messages:
    298
    Likes Received:
    8
    Best Answers:
    1
    Trophy Points:
    45
    #9
    It is the same unless you set the field to binary I believe^

    WHERE `name` = '$name'
    Code (markup):
    should do fine...
     
    Sky AK47, Nov 1, 2009 IP
  10. MisterSeller

    MisterSeller Peon

    Messages:
    35
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #10
    Haven't noticed any difference.

    Anyway, i was able to display all the usernames of the database without using the search function, so that means the problem is the search function itself.

    I've tried using Google to find some PHP written search engines, but those are way too complicated.

    Oh and can anyone answer the question above?
     
    MisterSeller, Nov 1, 2009 IP