$query "SELECT t.id FROM tags t, posts_tags pt WHERE pt.tag_id = t.id AND pt.post_id = :post_id";
使用此查询来关联这3个表
$ query“SELECT t.id FROM tags t,posts_tags pt WHERE pt.tag_id = t.id AND pt.post_id =:post_id”; 使用此查询来关联这3个表
[ POSTS ] [ TAGS ] [ POSTS_TAGS ]
| id | title | | id | name | | id | post_id | tag_id | tag_type|
|----|----------| |----|-------| |----|----------|--------|---------|
| 1 | PHP7 | | 1 | PHP | | 1 | 1 | 1 | 1 |
| 2 | HTML | | 2 | HTML | | 2 | 1 | 2 | 1 |
| 3 | CSS3 | | 3 | CSS | | 3 | 1 | 3 | 2 |
_________________ ______________ | 4 | 2 | 2 | 3 |
| 5 | 2 | 3 | 2 |
| 6 | 3 | 3 | 3 |
____________________________________
如何调用像这样排序的标签
Title: PHP7
Tags:
Lv1: PHP, HTML
Lv2: CSS
Lv3:
Title: HTML
Tags:
Lv1:
Lv2: CSS
Lv3: HTML
以某种方式简化为
Lv(n) = tag_ids WHERE tag_type = (n)
我想像这样回应它
echo"
<a>$tag</a> //LV1
<a>$tag</a> //LV2
<a>$tag</a> //LV3
";
而不是使用"WHERE tag_type = 1 ~ 2 ~ 3"