gpt4 book ai didi

php - 3个mysql表之间的关系

转载 作者:行者123 更新时间:2023-11-29 03:59:17 25 4
gpt4 key购买 nike

我有 3 个 mysql 表:事件、艺术家和(艺术家)描述。它们都是多对多关系。

表“事件”:

 ID | eventTitle | etc.
-----------------------
1 | event 1 |
2 | event 2 |
etc.

表“艺术家”:

 ID | artistName | etc.
-----------------------
1 | artist 1 |
2 | artist 2 |
etc.

表“描述”:

 ID | artistDesc             | etc.
----------------------------------
1 | artist 1 description 1 |
2 | artist 1 description 2 |
3 | artist 2 description 1 |
4 | artist 2 description 2 |
5 | artist 3 description 1 |
etc.

我还制作了连接表 events_artistsartists_desctriptions。它们都只有 2 个外键,并且仅用于链接事件、艺术家和描述 ID。

请注意我的描述表 - 每个艺术家都可以有很多描述。这实际上意味着每个描述只属于一个特定事件。 =)

如果我做这样的查询:

$q = "SELECT 
events.*,artists.*,descriptions.*,events_artists.*,artists_descriptions.*
FROM
events,artists,descriptions,events_artists,artists_descriptions
WHERE
events.eventID = events_artists.eventID AND
events_artists.artistID = artists.artistID AND
artists.artistID = artists_descriptions.artistID AND
artists_descriptions.descID = descriptions.descID";

我将获取特定艺术家的所有描述。但是没有任何描述会知道它们属于哪个事件......我想向用户显示的是这样的:

事件 1
艺术家 1(艺术家 1 描述 1)
艺术家 2(艺术家 2 描述 2)

事件 2
艺术家 3(艺术家 3 描述 6)
艺术家 1(艺术家 1 描述 3)

等等

我应该为事件描述关系制作联结表吗?如果我这样做,我不知道如何使用它,呃! =)或者我的问题可能无法通过简单的查询解决?我也应该用 php 做点什么吗?对不起,但我完全糊涂了 =)

我希望我能正确地解释我的问题...

在此先感谢您的帮助!

最佳答案

您应该合并 events_artistsdescriptions 表,使只有 1 个表将艺术家链接到事件和描述。

关于php - 3个mysql表之间的关系,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1540996/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com