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

    Joined:
    Aug 27, 2010
    #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: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


    HTML:
    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";
     
  2. Bostonaholic macrumors 6502

    Bostonaholic

    Joined:
    Aug 21, 2009
    Location:
    Columbus, Ohio
    #2
    Build a template for the sentence you want to build. So....

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

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

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

    Joined:
    Aug 27, 2010
    #3
    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