Heim  >  Artikel  >  Backend-Entwicklung  >  这条SQL查询语句什么意思啊解决办法

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

WBOY
WBOYOriginal
2016-06-13 13:53:47905Durchsuche

这条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% ') "啦

Stellungnahme:
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn