English 中文(简体)
如何在数据库表格中与先前判决的句子中的关键词相对应?
原标题:How to match key words in a sentence against pre-existing sentences in a database table?
  • 时间:2010-10-01 18:55:46
  •  标签:
  • php
  • mysql

我想插入“这pple,是一种果实”,来查询数据库,只能与数据库中未果的 words和水果相匹配,并交还1个水果 red。

如何修改询问法?

数据库名称食品领域如下:

id name1 name2 name3 name4 type
1 fruit apple red 10 article
2 fruit banana yellow 12 article
3 drink beer yellow 6 article
4 fruits apple yellow 16 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 name1, name2 like  %$match%  ");
$row=mysql_fetch_array($query);
echo $row[ id  ]. "r" .$row[ name1 ]. "r".$row[ name2 ]. "r".$row[ name3 ]. "r".$row[ name4 ]. "n";
问题回答

It s hard to tell, but I think if you are trying to avoid returning anything that does not equal the exact word (apples != apple). You will have to break your $match string into smaller parts and check for them individually. maybe use explode() to break the string apart using white spaces and then do exact matches on the words that apply.

目前 你们正在核对数据库中任何数据,这些数据可能与任何方面相似。 因此,只要有“是”、“a”和“fruit”等词,它就可以回去“pple是果实”。

或许也值得重新命名贵国的数据库栏。 没有人看一看一面有名称1、姓名2、名称3. 如何打字、姓名、col、mount?

$match = trim($match);
$match = strtolower($match);
$newmatch = explode(" ",$newmatch);

So if $match was "This is an apple" $newmatch = array("this","is","an","apple")

当然,这一胜利已经摆脱了任何旁观。 但是,如果你喜欢三点和预选点,你可以这样做。

Help: trim() , strtolower() , explode()





相关问题
SQL SubQuery getting particular column

I noticed that there were some threads with similar questions, and I did look through them but did not really get a convincing answer. Here s my question: The subquery below returns a Table with 3 ...

please can anyone check this while loop and if condition

<?php $con=mysql_connect("localhost","mts","mts"); if(!con) { die( unable to connect . mysql_error()); } mysql_select_db("mts",$con); /* date_default_timezone_set ("Asia/Calcutta"); $date = ...

php return a specific row from query

Is it possible in php to return a specific row of data from a mysql query? None of the fetch statements that I ve found return a 2 dimensional array to access specific rows. I want to be able to ...

Character Encodings in PHP and MySQL

Our website was developed with a meta tag set to... <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> This works fine for M-dashes and special quotes, etc. However, I ...

Pagination Strategies for Complex (slow) Datasets

What are some of the strategies being used for pagination of data sets that involve complex queries? count(*) takes ~1.5 sec so we don t want to hit the DB for every page view. Currently there are ~...

Averaging a total in mySQL

My table looks like person_id | car_id | miles ------------------------------ 1 | 1 | 100 1 | 2 | 200 2 | 3 | 1000 2 | 4 | 500 I need to ...

热门标签