简体   繁体   English

就受欢迎程度而言,可排序的标签列表?

[英]sortable tag lists, in terms of popularity?

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.. 等等..

i assume you have a table tags , posts and posts_tags (you haven't told us what you want to tag …) to associate them 我假设您有一个表格tagspostsposts_tags (您尚未告诉我们要标记的内容...)来关联它们

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM