显示数据库中的主题标签(Displaying hashtags from the db)
我有一个问题,即我想显示来自这样的表“帖子”的主题标签:
| id | author | hashtags | |:------------|-------------:| | 1 | aaaa | #aaa, #bbbb | etc... | 2 | bbbb | #ccc, #addd | | 3 | cccc | #aee, #ffff |问题是我想得到这样的东西(只有那些记录):
When I write a: #aaa, #addd, #aee When I write b: #bbbb etc...我如何得到只有那些以字母开头的标签(即使在同一个字段中)出现的效果? 我在考虑正则表达式。 在此先感谢您的帮助。
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.
最满意答案
您需要进行一些更改:
将hashtags列移动到新表并将不同的hashtags存储在不同的行中(post id作为外键)即规范化表使用LIKE运算符查询新表,例如
SELECT hashtag FROM post_hashtag WHERE post_id = <id> AND hashtag LIKE '%#a%';`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 tableuse LIKE operator to query on the new table, e.g.
SELECT hashtag FROM post_hashtag WHERE post_id = <id> AND hashtag LIKE '%#a%';`更多推荐
发布评论