mysql - 博客文章标签表结构设计问题
天蓬老师
天蓬老师 2017-04-17 15:55:13
0
2
411

感觉segmentfault站点设计的标签还是很不错的,正在写一个博客平台,想做个文章标签,现在表设计如下:

文章表(articles)

id title tags
1 xxx 1,3,4
2 aaa 2,4
3 bbb 3,5

标签表(tags)

id name
1 php
2 javascript
3 mysql
4 css3
5 html5

假如信息结构如上面,那么怎么取出每篇文章的详细信息呢?上面的表设计可以实现吗?

我查了下本站的相关问题,有人说再加入第三章标签文章关联表,如下面

标签关联表(tag_links) tidtagsid,aid是文章articlesid

id tid aid
1 1 1
2 3 1
2 4 1

那么这个有怎么查出文章的详细信息呢?

天蓬老师
天蓬老师

欢迎选择我的课程,让我们一起见证您的进步~~

reply all(2)
黄舟

Generally, the table is built in the following way. If you want to query detailed information, you can first check some information about the article in the article table based on the article ID, and then use the article ID to join the tag table and the article tag association table to query. Label data, finally merge these two arrays.

A little suggestion: You can split the article table horizontally, you can take out the content fields and make a separate table, and use ID to key. This is more efficient when the amount of data is large,

These are my personal opinions. If there is something wrong, I hope the experts can point me out

大家讲道理

I happen to be writing a blog, and I also encountered this problem, 3 tables are related, and now I have a problem with the sql statement
Please give me the Sql statement

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!