sortable tag lists, in terms of popularity?
I want to implement a tag list, for instance, top ten tags used in the website. Are th开发者_开发技巧ere 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..
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
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
精彩评论