Reputation:
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?
Upvotes: 0
Views: 80
Reputation: 13525
You can use IN
keyword
SELECT COUNT(id)
FROM #__content
WHERE access IN ($niveis)
Upvotes: 1
Reputation: 1269603
You can use find_in_set()
:
select count(id)
from #__content
where find_in_set(access, $niveis) > 0;
Upvotes: 0