php search script need help

Discussion in 'PHP' started by moon_gfx77, Sep 4, 2010.

  1. #1
    dear friends i am new php learner
    i have a search script which bring fetch data
    only by single keyword "online"
    i want to make multiple keyword search like "online real estate"
    here is my code

    $sp = trim($_POST['art']);
    $sp = preg_replace('/\s+/','',$sp);

    if($sp == ''){
    echo 'keyword required';
    }
    else
    {
    $con = mysql_connect("xxxxxxxx","xxxxxxx","xxxxxxx");
    if (!$con)
    {
    die('Could not connect: ' . mysql_error());
    }

    mysql_select_db("engine", $con);

    $result = mysql_query("SELECT * FROM tablename WHERE name LIKE '%$sp%' OR phone LIKE '%$sp%' OR keyword LIKE '%$sp%' OR city LIKE '%$sp%'");

    while($row = mysql_fetch_array($result))
    {
    echo $row['name'] . " " . $row['phone'];
    echo "<br />";
    }
    }
    ?>
     
    moon_gfx77, Sep 4, 2010 IP
  2. HuggyEssex

    HuggyEssex Member

    Messages:
    297
    Likes Received:
    4
    Best Answers:
    2
    Trophy Points:
    45
    #2
    Just a simple like will search a whole field for a match.
     
    HuggyEssex, Sep 4, 2010 IP