数据库名 '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显然不能满足,求助,谢谢。
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显然不能满足,求助,谢谢。
是不是这样写:
SELECT * FROM food WHERE MATCH (name2) AGAINST (‘$match’);
然后呢?
如果数据过多的话,mysql的反应会更慢。