#1
  1. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2000
    Posts
    1
    Rep Power
    0
    Hello.. I'm Portuguese... and i start with PHP recently...

    Can you help me... I have a search engine which works with MySQL...

    How can i search with two or more words...

    for example:

    Search: music rock

    And the results are : everything wich contains the words music and/or rock


    Thanks Very Much
  2. #2
  3. No Profile Picture
    Apprentice Deity
    Devshed Loyal (3000 - 3499 posts)

    Join Date
    Jul 1999
    Location
    Niagara Falls (On the wrong side of the gorge)
    Posts
    3,237
    Rep Power
    19
    select * from table_name where search_field like '%$first_term%' or search_field like '%$second_term%'
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2000
    Posts
    79
    Rep Power
    15
    <?
    #say...
    $query = "music rock";
    #you could split these using explode()
    $splitquery = explode(" ",$query); //split where there is a space
    $number = count($splitquery); //count the number of elements splitted to

    #beginning of database query
    $q1= "select * from $urls_table where ";

    #second part of query
    $i = 0;
    while ($i<$number) //while there are still array elements to go
    {
    $q1 .= "field LIKE '%$splitquery[$i]%' OR ";
    $i++; //increment $i
    }

    #remove the extra " OR" from the end
    $q1 = substr($q1,0,-3);

    echo "$q1"; //just so u can see it works

    mysql_query($database,$q1);

    ?>

    this one took me a little while...works for me so should work for you

    good luck
    Basil


    [This message has been edited by 'tantrum (edited June 17, 2000).]

Similar Threads

  1. alt. search strategies for words w/ < 3 letters
    By aberns in forum MySQL Help
    Replies: 2
    Last Post: January 28th, 2004, 06:29 AM
  2. Cgi Search feature script
    By butsy_7 in forum Perl Programming
    Replies: 5
    Last Post: January 22nd, 2004, 08:43 PM
  3. Is there any alternative to fulltext search?
    By irishairpics in forum MySQL Help
    Replies: 2
    Last Post: December 10th, 2003, 03:40 PM
  4. Macro word to extract words according to dictionary
    By pingucain in forum Visual Basic Programming
    Replies: 4
    Last Post: November 10th, 2003, 05:01 AM

IMN logo majestic logo threadwatch logo seochat tools logo