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.

php/mysql search engine

Discussion in 'MySQL' started by lv211, Jul 23, 2008.

  1. #1
    I'm building a search engine from scratch.

    My sql query is not giving me the output I would like. If I partially enter a word it will not match the query. If I enter the word exactly it will not match it all the time.

    Here is my query:

    $query = "SELECT DISTINCT * FROM `table` WHERE `name_id` LIKE '%$search%' ORDER by name_id ASC";
     
    lv211, Jul 23, 2008 IP
  2. sscheral

    sscheral Peon

    Messages:
    24
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    I think you need to append the content of $search variable

    $query = "SELECT DISTINCT * FROM `table` WHERE `name_id` LIKE '%" + $search+ "%' ORDER by name_id ASC";
     
    sscheral, Jul 24, 2008 IP
  3. lv211

    lv211 Peon

    Messages:
    168
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #3
    That doesn't work. I get an error.

    Are you trying to concantate the string with the +'s?

    I'm using PHP.
     
    lv211, Jul 25, 2008 IP
  4. garrettheel

    garrettheel Peon

    Messages:
    341
    Likes Received:
    11
    Best Answers:
    0
    Trophy Points:
    0
    #4
    There's nothing wrong with your query.. no reason why it shouldn't work.
     
    garrettheel, Jul 26, 2008 IP
  5. david_t

    david_t Member

    Messages:
    74
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    45
    #5
    That is not the problem. When you use double quotation mark in php, it's perfectly fine to use variables directly inside of them.

    And when you are concatenating strings in php you use a punctuation mark instead of a plus sign.

    The query looks perfectly fine to me. Are you sure the variable $search is exactly what you think it is?
     
    david_t, Jul 26, 2008 IP
  6. garrettheel

    garrettheel Peon

    Messages:
    341
    Likes Received:
    11
    Best Answers:
    0
    Trophy Points:
    0
    #6
    I assume you have a $search = $_POST['search']; in the script before, yes?
     
    garrettheel, Jul 26, 2008 IP
  7. xlcho

    xlcho Guest

    Messages:
    532
    Likes Received:
    8
    Best Answers:
    0
    Trophy Points:
    0
    #7
    Maybe you should use ILIKE ? This could be the problem, since theres nothing wrong with the query
     
    xlcho, Jul 27, 2008 IP
  8. tamaldg

    tamaldg Peon

    Messages:
    2
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #8
    :confused: Hi, I am a fresher php coder having very few knowledge. My question is:

    I want to achieve search result following way:

    say I have 13 listing under a certain keyword.

    when someone will search the keyword, then the search result will show 1-10,

    then when the same person searches the same keyword second time, the the search result will show 2-11,

    thus, then if i search the keyword again, the search result will show 3-12.

    can it be achieved ? if yes, then how ?
     
    tamaldg, Jul 30, 2008 IP
  9. garrettheel

    garrettheel Peon

    Messages:
    341
    Likes Received:
    11
    Best Answers:
    0
    Trophy Points:
    0
    #9
    This is called pagination. Do a google search and you'll find plenty of tutorials to help you do it.
     
    garrettheel, Jul 30, 2008 IP
  10. andrewgjohnson

    andrewgjohnson Active Member

    Messages:
    180
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    53
    #10
    Few things:

    • Your query in theory works fine - are you sure it SHOULD be returning rows?
    • I'd suggest concatenating to avoid confusion on what is a variable and what isn't - however you use periods (.) instead of pluses (+) to do this in PHP
    • Using a "SELECT *" and a "WHERE col LIKE '%'" is going to end up being very slowly if your site ever becomes popular or the database becomes large - I commend you for trying to build something new but perhaps you should rethink your query and platform
     
    andrewgjohnson, Jul 30, 2008 IP
  11. lv211

    lv211 Peon

    Messages:
    168
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #11
    Yeah.. I found out about Sphinx Search. I'm going to try to implement that on my site instead of building a new engine.

    Trying to start a search engine from scratch was a lot more difficult than I planned.
     
    lv211, Jul 30, 2008 IP
  12. falcondriver

    falcondriver Well-Known Member

    Messages:
    963
    Likes Received:
    47
    Best Answers:
    0
    Trophy Points:
    145
    #12
    agree, you need some more tables. a wordtable where you store each word you found on websites (without the stopwords like "the, then, there, we, me, i, in, of" etc.) and then a second where you store the website_id together with the word_id. your wordtable stays pretty small this way (there are only ~3-5000 common words in english) and the search is much faster than 'LIKE'.
    however, "building a search engine" is nothing you can do as a newbie over the weekend.
    understanding the human language is very difficult - thats why computer translators and search engines still suck so much.
     
    falcondriver, Jul 30, 2008 IP
  13. tamaldg

    tamaldg Peon

    Messages:
    2
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #13
    Hi, I want to make a search system, where the first search result row will be moved to the end of the mysql table, so that when next time some of my website visitor will search for the same term, the previous first position result will appear at the end of the search result.

    for example: Tom searches my search engine for the keyword "wine company" , he get result with "ABC wine company" at 1st position and "XYZ wine company" ant 2nd position on the result page.

    Then if Tom or anyone else searches my search engine again with the same keyword, the result page will show "XYZ wine company" at first position and "ABC wine company at last position.

    Thus I want a rotation of the search result. So that no one can enjoy a static 1st position on my search engine.

    Please help
     
    tamaldg, Aug 3, 2008 IP