Home > Backend Development > PHP Tutorial > 这条SQL查询语句什么意思啊解决办法

这条SQL查询语句什么意思啊解决办法

WBOY
Release: 2016-06-13 13:53:47
Original
968 people have browsed it

这条SQL查询语句什么意思啊
今天在看代码!看到这里晕了!!请大虾们看看!
$sql= "SELECT   lid,   title,   htmlfile,   add_time   FROM   zixun_list   WHERE   tid= '$tid '   AND   lid '$lid '   AND   (keyword   LIKE   '% ".preg_replace( "/(,|,)/ ",   "% '   OR   keyword   LIKE   '% ",   stripslashes($keyword)). "% ')   ORDER   BY   lid   DESC   LIMIT   2 ";

特别是这个:(keyword   LIKE   '% ".preg_replace( "/(,|,)/ ",   "% '   OR   keyword   LIKE   '% ",   stripslashes($keyword)). "% ')

------解决方案--------------------
比如$keyword = "a,b ";
preg_replace( "/(,|,)/ ", "% ' OR keyword LIKE '% ", stripslashes($keyword));
就是把$keyword字符串中的逗号替换为字符串 % ' OR keyword LIKE '%
那么
"(keyword LIKE '% ".preg_replace( "/(,|,)/ ", "% ' OR keyword LIKE '% ", stripslashes($keyword)). "% ') "
就变成
"(keyword LIKE '%a% ' OR keyword LIKE '%b% ') "啦

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