我的表中有一个名为to_user
的列,其内容如下:
id to_user
1. 1+2+3
2. 1
我的查询
select
* from notifications
where (type = 4 and to_user LIKE %+".$user_id."+%)
or (to_user REGEXP +?".$user_id."+? ) and status = 2
但它不起作用。
答案 0 :(得分:1)
你应该用正确的引号括起搜索条纹(并删除+如果不是你的sarch条件的字符串)
"select * from notifications where (type = 4 and to_user LIKE '%".$user_id."%')
or (to_user REGEXP '".$user_id."' ) and status = 2" ;
因为你正在使用字符串,如果你需要一个确切的macth is = is not like like而且不要使用正则表达式
答案 1 :(得分:1)
$sql = "SELECT *
FROM notifications
WHERE (type = 4 and to_user
LIKE '%" . $user_id . "%')
OR (to_user REGEXP '\+" . $user_id . "\+' )
AND status = 2";