mysql query help

Discussion in 'MySQL' started by moon_gfx77, Sep 6, 2010.

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

    "online real estate"
    "real estate online"
    "real online estate"

    here is my code Kindly help

    $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 6, 2010 IP
  2. mwasif

    mwasif Active Member

    Messages:
    816
    Likes Received:
    23
    Best Answers:
    1
    Trophy Points:
    70
    #2
    mwasif, Sep 6, 2010 IP