How to put a sentence to match the database?

Discussion in 'Web Design and Development' started by youlichika, Oct 1, 2010.

  1. youlichika macrumors member

    Aug 27, 2010
    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:confused:, 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%' ");
    echo $row['id ']. "r" .$row['name1']. "r".$row['name2']. "n";
  2. Bostonaholic macrumors 6502


    Aug 21, 2009
    Columbus, Ohio
    Build a template for the sentence you want to build. So....

    Tim likes orange juice.
    Replace with the fields you're getting from the DB.

    Tim likes $row['name2'] $row['name3'].
    Convert to php echo.

    echo "Tim likes $row['name2'] $row['name3'].";
  3. youlichika thread starter macrumors member

    Aug 27, 2010
    Hi, Bostonaholic. It is hard to build a template.
    Because the diferent sentence has a diferent word order.
    sentence A is 'This is a apple, it is a fruit'
    sentence B is 'Tim likes orange juice'
    There also has sentence C or D... ...

Share This Page