日期:2014-05-17  浏览次数:20548 次

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