像在sql中有很多值的%

Joh*_*ohn 2 php mysql sql

如何在sql中用太多的值编写类似的%查询?

例如,请参阅表格结构

Id Tid name
1  1   test
2  3   ram
3  10  felix

select * from table where Tid Like % 1,10 %
Run Code Online (Sandbox Code Playgroud)

另外我把这个值放在一个表单中,所以post变量值就像$_POST['tid']=1,10 我将要实现的那样

select * from table where Tid Like % $_POST['tid'] %
Run Code Online (Sandbox Code Playgroud)

谢谢 .

Gor*_*off 6

MySQL提供find_in_set():

where find_in_set(Tid, '1,10') > 0
Run Code Online (Sandbox Code Playgroud)

请注意,这不会使用索引.您可以implode()在php中使用in而不是,导致:

where tid in (1, 10)
Run Code Online (Sandbox Code Playgroud)