Home > Backend Development > PHP Tutorial > 怎么让数组中多个成员,匹配MYSQL单字段里的一篇文章

怎么让数组中多个成员,匹配MYSQL单字段里的一篇文章

WBOY
Release: 2016-06-13 12:07:11
Original
1131 people have browsed it

如何让数组中多个成员,匹配MYSQL单字段里的一篇文章。
例如
数组:

$arr=array('tom','cat','jam','tim','bim');
Copy after login


mysql 中的 文章字段 内容如下
第一条字符串
tom,cat,tony,girl
Copy after login

第二条字符串
jam,tim,bim
Copy after login

第三条字符串
jam,tom
Copy after login

第四条字符串
tool,wood,boy,cat
Copy after login


通过这个数组怎么把下面四条全部匹配出来
------解决思路----------------------
$sql = 'create temporary table T ';<br />foreach($arr as $i=>$v) {<br />  $sql .= $i ? "union select '$v' " : "select '$v as name ";<br />}<br />mysql_query($sql); //创建临时表<br /><br />$sql = "select * from tbl_name, T where find_in_set(T.name, tbl_name.field)";<br />$rs = mysql_query($sql); //查询<br />
Copy after login

------解决思路----------------------
如果查询的比较多用全文搜索,最直接且很快,
再者你的词有逗号分隔,那么分词就特别容易了。
------解决思路----------------------
把下面的字符串变成数组,与上面的数组比较,如果数组有相同元素,就把当前字符串记录下来。

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template