这条SQL查询语句什么意思啊解决办法
程序员文章站
2022-06-02 16:43:45
...
这条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% ') "啦
今天在看代码!看到这里晕了!!请大虾们看看!
$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% ') "啦
相关文章
相关视频