显示数据库中的主题标签

显示数据库中的主题标签

问题描述:

I have a problem, namely I want to display hashtags from such table "posts":

| id | author |   hashtags   |
|:------------|-------------:|
|  1 |  aaaa  | #aaa, #bbbb  | etc...
|  2 |  bbbb  | #ccc, #addd  |
|  3 |  cccc  | #aee, #ffff  |

The problem is that I would like to get something like this (only those records):

When I write a: #aaa, #addd, #aee
When I write b: #bbbb
etc...

How do I get the effect that only those hashtags that start with a letter (even in the same field) appear to me? I was thinking about regular expressions. Thanks in advance for any help.

我有一个问题,即我想显示来自这样的表“posts”的主题标签: p>

  |  id | 作者|  hashtags | 
 |:------------ | -------------:| 
 |  1 |  aaaa |  #aaa,#bbbb | 等.. \ N |  2 |  bbbb |  #ccc,#add | 
 |  3 |  cccc |  #aee,#ftff | 
  code>  pre> 
 
 

问题在于我想得到类似的东西(只有那些记录): p> 当我写一个:#aaa,#add,#aee 当我写b:#bbbb etc ... code> pre>

怎么做 我觉得只有那些以字母开头的标签(即使在同一个字段中)出现在我身上? 我在考虑正则表达式。 在此先感谢您的帮助。 p> div>

You need to make a couple of changes:

  • Move hashtags columns to a new table and store different hashtags in different rows (with post id as foreign key) i.e. normalize the table
  • use LIKE operator to query on the new table, e.g.

    SELECT hashtag
    FROM post_hashtag
    WHERE post_id = <id>
    AND hashtag LIKE '%#a%';`