views:

49

answers:

2

I want to implement a tag list, for instance, top ten tags used in the website. Are there any tutorials or articles that can help me to create this!

For example:

#topic  (200 mentions)
#topic (150 mentions)
#topic (50 mentions) ....

and so on..

A: 

Without more information, this is strictly a guess given the lack of information, but here is the query that should do it if you customize it to your system.

SELECT tag, (
              SELECT count(*) 
              FROM mentions 
              WHERE tags.id = mentions.tags_id
             ) as count 
FROM tags 
ORDER BY count DESC
Brad F Jacobs
+1  A: 

i assume you have a table tags, posts and posts_tags (you haven't told us what you want to tag …) to associate them

you then want to count the number of times a tag was used:

    select count(*)
      from `posts_tags` pt
inner join `tags` t
        on pt.tagid = t.tagid
  group by t.tagid
  order by count(*) desc
     limit 10
knittl