Need help with my PHP search script!!??

Discussion in 'Web Design & Coding' started by DAZZ, Feb 19, 2003.

  1. DAZZ

    DAZZ Guest

    Hi, I have a search script in PHP which searches a MYSQL DB table for websites, and what's on them. The current setup is:

    'number' the number of the website
    'url' the url of the website
    'contains' this is where the search script searches in, and its whats on the website.

    The searching works great, but I need something to be added to it....

    For example, I have the the sites http://www.yahoo.com/ and http://www.php.net/ in the databas, setup like so...

    '1' 'http://www.yahoo.com/ 'search, good search engine, the.greatest.search, good.place'

    '2' 'http://www.php.com/ 'php, php makers, great.info'

    As you see, each 'keyword' is seporated by a comma ',' And when someone searches for, let's say "good"....this would show up...

    SITE NUMBER '1'
    URL: http://www.yahoo.com
    Contains: search, good search engine, the.greatest.search, good.place

    it displays that, because the word good is in the contains field of this website

    But what im wanting to do is to make it so when someone searches for "good" this will come up...

    SITE NUMBER '1'
    URL: http://www.yahoo.com/
    Contains: good search engine, good.place

    What happens is, it takes away everything that doesnt contain "good" in it, it takes away 'search, the.greatest.search'

    I know it would be possible, because of the commas ',' just do something with them to make this possible..

    Im really new to php, so i dont know anything....

    PLease try to help me out, this is important, thank you!!!

    If you don't understand something, please tell me, I really need this working!!

    Thanks
     
  2. Zedric

    Zedric NTFS Guru Folding Team

    Messages:
    4,006
    Location:
    Sweden
    I'd use explode() to split the string, search each piece for "good" and then reassemble the ones containing "good". I think that's the easiest way. :)
     
  3. DAZZ

    DAZZ Guest

    im really new to PHP, and i really wouldnt know where to start with that, could i just send you my entire PHP search script, and u can look it over??

    pleeease
     
  4. Zedric

    Zedric NTFS Guru Folding Team

    Messages:
    4,006
    Location:
    Sweden
    Ok, just attach it.
     
  5. DAZZ

    DAZZ Guest

  6. Zedric

    Zedric NTFS Guru Folding Team

    Messages:
    4,006
    Location:
    Sweden
    Try this before printing $replaced. (Untested code)

    PHP:
    $keyarr explode($replaced",");
    $replaced "";
    for(
    int $i=0;$i<sizeof($keyarr);$i++){
        if(
    stristr($keyarr[$i], $search)){
            
    $replaced .= $keyarr[$i] . ",";
        }
    }
    // Remove trailing comma
    $replaced substr($replaced0strlen($replaced) - 2));
     
  7. DAZZ

    DAZZ Guest

    i get...

    Parse error: parse error, unexpected T_VARIABLE, expecting ';' in /www/www2/123/search.php on line 73
    :huh: :huh:
     
  8. DAZZ

    DAZZ Guest

    help?
     
  9. Geffy

    Geffy Moderator Folding Team

    Messages:
    7,805
    Location:
    United Kingdom
    show us line 73, or you can just check to see if there is a ; at the end of the line or the line before it.
     
  10. Zedric

    Zedric NTFS Guru Folding Team

    Messages:
    4,006
    Location:
    Sweden
    Umm, my bad. Skip "int ".

    PHP:
    $keyarr explode($replaced",");
    $replaced "";
    for(
    $i=0;$i<sizeof($keyarr);$i++){
        if(
    stristr($keyarr[$i], $search)){
            
    $replaced .= $keyarr[$i] . ",";
        }
    }
    // Remove trailing comma
    $replaced substr($replaced0strlen($replaced) - 2));
    I told you I hadn't tested the code! :p (still haven't)