使用字符串作为条件计算SQL中的行数

I have the string $niveis with the following values (example):

3,8,10

Using this string, I need to count the number of rows in table content, where the access matches any of these 3 values.

For example, if table content is:

id   access
1    2
2    3
3    3
4    7
5    8
6    9
7    10
8    10

Should return 5.

I tried the following query in PHP:

$query="SELECT count(id) FROM #__content WHERE access =$niveis";

But it isn't working, can anyone help?

You can use IN keyword

SELECT COUNT(id)
FROM #__content
WHERE access IN ($niveis)

You can use find_in_set():

select count(id)
from #__content
where find_in_set(access, $niveis) > 0;