数据库名 'food' 字段如下:
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";
如何把一个句子进行数据库匹配?类似于“This is a apple, it is a fruit”。我想把整句句子作为关键字搜索,根据“apple,fruit”,只得出“1    fruit   apple ”而不是“5    food    applepie ”或者“6    food    apple tin”;
如果句子改成“Tim likes orange juice”,根据关键字orange juice,只得出“8    drink   orange juice”而不是“7    fruit   orange ”
like显然不能满足,求助,谢谢。

解决方案 »

  1.   

    用FULLTEXT 应该可以实现你的要求。
      

  2.   

    不懂全文检索,
    是不是这样写:
    SELECT * FROM food WHERE MATCH (name2) AGAINST (‘$match’);
    然后呢?
      

  3.   

    你可以看看mysql的fulltext,就知道了
      

  4.   

    为什么会有这样的需求?不能换一种方法么?即使搜索了,但是效率会非常低。
    如果数据过多的话,mysql的反应会更慢。
      

  5.   

    “数据库名 'food' 字段如下:”这里应该是数据表名,写数据库名称容易照成误解。
      

  6.   

    '%$match%' %-->这个是通配符 ,不要它了 试一下看