显示数据库中的主题标签(Displaying hashtags from the db)

编程入门 行业动态 更新时间:2024-10-25 14:29:59
显示数据库中的主题标签(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 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%';`

更多推荐

本文发布于:2023-08-06 14:19:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1451308.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:数据库中   标签   主题   db   Displaying

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!