Using DISTINCT and COUNT together in a MySQL Query
I would do something like this:
Select count(*), productid
from products
where keyword = '$keyword'
group by productid
that will give you a list like
count(*) productid
----------------------
5 12345
3 93884
9 93493
This allows you to see how many of each distinct productid ID is associated with the keyword.
You were close :-)
select count(distinct productId) from table_name where keyword='$keyword'
use
SELECT COUNT(DISTINCT productId) from table_name WHERE keyword='$keyword'