php mysql select and count

askerman :

I have mysql table named 'tagtable' and it has text type column 'params' column like below;

id   tag                 params    //in text type 
1   #discount          {"activity":[105,106,107]}
2   #table             {"activity":[108,109,110,111]}
3   #pencil            {"activity":[112,113]}
4   #door              {"activity":[114]}
5   #phone             {"activity":[115]}
6   #wall              {"activity":[116,117,118,119,120]}
7   #radio             {"activity":[121,122,123]}

my expexted result is selecting top 4 tag with most activity number count from text type params column and counting them, like below:

#wall-5  , #table-4 , #discount-3, #radio-3

How can I achieve that with php ?

Tushar :

Try this code

SELECT 
ID, 
tag, 
(CHAR_LENGTH(params) - CHAR_LENGTH(REPLACE(params, ',', '')) + 1) as total 
FROM tagtable 
order by total desc 
limit 4

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=170365&siteId=1