1

我是 Web 开发的新手,正在学习我们正在使用 PHP 和 MySQL 开发网站的课程。

我正在做一个项目,我将拥有很多用户,每个用户都有一个或多个日历,每个日历都有一个或多个事件。

从逻辑上讲,事件是日历表中具有日期时间、标题、位置等的一行是有意义的。

我的问题是:

我如何本质上将“指针”存储到另一个表的一行中的表?

例如,假设用户有一个运动日历和一个工作日历。我了解如何为这些日历中的每一个创建表并向它们添加事件,但是如何存储有关如何在我的用户行中检索它们的信息。

用户将有列

  • 用户 ID(自动递增),
  • 电子邮件,
  • 用户名,
  • 密码(哈希),
  • 盐,
  • 和日历。)
4

3 回答 3

1

您只需userId在日历的表格中放置一列。每当您需要它们时,您就可以在这些表中查询它。这是您需要的唯一参考。

而且你不应该在用户表中引用日历,因为用户可以有多个日历,你应该很好地使用userId日历表中的 as 外键。

于 2013-11-12T00:55:53.347 回答
0

You will need basically three tables here one for Users another for Calendar and another for Event.

And the relationship would be a User could have many calendars and a Calendar could have many Events.

It would probably look like this:

TABLE Name : Users 
Fields     : userid(auto-incremented), email, username, password(hash), salt

TABLE Name : Calendars 
Fields     : CalendarID, userid, dateFrom, dateTo, Category

TABLE Name : Events
Fields     : EventID, CalendarID, Description

And your SQL would probably look like this:

To get the calendar of a given user would be:

SELECT CalendarID, dateFrom, dateTo, Category
FROM Calendars
WHERE userid = <user id here>

And to get the events of that calendar of a given user would probably look like this:

SELECT Calendars.CalendarID, dateFrom, dateTo, Category, Description
FROM Calendars
INNER JOIN Events
ON Calendars.CalendarID = Events.CalendarID
WHERE userid = <user id here>
于 2013-11-12T01:01:49.450 回答
0

My logic is different than your logic. My idea of a calendar table would have a single row for each date. Other columns would contain information about that date, such as fiscal or school year, plus holidays.

For user appointments, depending on the level of detail required, I would simply store a user id, and event id. The event would have a start and end datetime and category id.

I would be working towards something where each user only has one set of appointments to maintain.

于 2013-11-12T01:02:48.873 回答