php对帖子分类,php – MySQL:从类别中获取帖子
我正在嘗試學習MySQL,所以我創建了一個小博客系統.
我在MysqL中有3個表:
帖子:
id | title
----------------
1 | Post Title 1
2 | Post Title 2
類別:
id | title | parent
--------------------------------
10 | category10 | 0
11 | category11 | 0
12 | category12 | 10
post_category_relations:
id | post_id | category_id
----------------------------------
1 | 1 | 10
2 | 2 | 12
3 | 3 | 11
每個帖子可以有多個類別,它們的關系存儲在post_category_relations中:
因此,當我訪問index.PHP?category = 10時,我想讓每個帖子與category10相關,包括其子文件夾category12中的帖子.
PHP中我未完成的片段
$folder_id = $_GET["category"]; // Get Category ID from the URL
$sql = "SELECT * FROM posts
JOIN categories
JOIN post_category_relations
// And I don't really know what should I do here
// because I need the child categories first,then the relations
// then I can get the post too from the post_id of the relations
";
MysqL_query($sql);
我知道這將需要高級MysqL技能,但任何幫助表示贊賞!我已經用PHP制作了這個,但我需要使用4個循環,這不是最好的方法,當它在MysqL中可能時,我只是不知道如何:)
創作挑戰賽新人創作獎勵來咯,堅持創作打卡瓜分現金大獎總結
以上是生活随笔為你收集整理的php对帖子分类,php – MySQL:从类别中获取帖子的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: python celery应用场景_py
- 下一篇: ajax respon有数据,Ajax怎