How to put a sentence to match the database?

Discussion in 'PHP' started by youlichika, Oct 1, 2010.

  1. #1
    How to put a sentence to match the database? The sentence like 'This is a apple, it is a fruit'. I want to separate the word apple to match the database, and it just echo '1 fruit apple' not '5 food applepie' or '6 food apple tin
    Or type other sentence like 'Tim likes orange juice', it just echo '8 drink orange juice'
    not '7 fruit orange' . It is too hard for me, needs help. Thanks.

    database name 'food' fields as below:
    id name1 name2 name3 name4 type
    1 fruit apple red 10 article
    2 fruit banana yellow 12 article
    3 drink beer yellow 6 article
    5 food applepie yellow 16 books
    6 food apple tin red 8 books
    7 fruit orange orange 5 article
    8 drink orange juice orange 11 books


    mysql_connect("localhost", "root", "root") or die(mysql_error());
    mysql_select_db("article") or die(mysql_error());
    ... ...
    echo $match . "r"; // $match= This is a apple, it is a fruit
    $query = mysql_query("SELECT * FROM food WHERE name2 like '%$match%' ");
    $row=mysql_fetch_array($query);
    echo $row['id ']. "r" .$row['name1']. "r".$row['name2']. "n";
    HTML:
     
    youlichika, Oct 1, 2010 IP