Answer the question
In order to leave comments, you need to log in
How to organize the table of achievements on the site?
Hello!
The idea is simple, there is a table user
+----+-----------+
| id | user_name |
+----+-----------+
| 1 | Dima |
| 2 | Sveta |
| 3 | Katya |
| 4 | Jenya |
+----+-----------+
user
, for example, id
and which will store the achievements of users in the training program on the site! the first thing that comes to mind considering my 3 weeks experience of learning skl is....+-----------------+----------+----------------+-----------------+---------------+
| achievements_id | users_fk | pass_first_lvl | pass_second_lvl | invite_friend |
+-----------------+----------+----------------+-----------------+---------------+
| 1 | 1 | 1 | 0 | 1 |
| 2 | 2 | 0 | 0 | 1 |
| 3 | 3 | 1 | 0 | 0 |
| 4 | 4 | 0 | 0 | 1 |
+-----------------+----------+----------------+-----------------+---------------+
achievements_id
, this is the primary key, and users_fk
this is a foreign key associated with the table user
by field id
, where in the cell , of 1
course, the achievement is received, but where, 0
what would you think...? Achievement not completed yet! But the question immediately arises: +-----------------+----------------------+---------------------+----------------------+--------------------+
| achievements_id | achievements_date_fk | pass_first_lvl_date | pass_second_lvl_date | invite_friend_date |
+-----------------+----------------------+---------------------+----------------------+--------------------+
| 1 | 1 | 2021-12-05 | 0000-00-00 | 2020-04-01 |
| 2 | 2 | 0000-00-00 | 0000-00-00 | 1987-11-03 |
| 3 | 3 | 2011-05-05 | 0000-00-00 | 0000-00-00 |
| 4 | 4 | 0000-00-00 | 0000-00-00 | 2019-07-16 |
+-----------------+----------------------+---------------------+----------------------+--------------------+
user
by id
Answer the question
In order to leave comments, you need to log in
Despite the fact that you have drawn several tables, from what you write, it is clear that all these tables are the same (one-to-one relationship), i.e. there is no normalization.
A user can have many achievements, of different types, so there should be a one-to-many relationship, something like:
+-----------------+----------+----------------+-----------------+
| achievements_id | users_fk | type | date |
+-----------------+----------+----------------+-----------------+
| 1 | 1 | 1 | 2021-10-01 |
| 2 | 2 | 1 | 2021-10-04 |
| 3 | 1 | 2 | 2021-10-08 |
| 4 | 1 | 4 | 2021-10-15 |
+-----------------+----------+----------------+-----------------+
+-----------------+-----------+----------------+-----------------+
| achieve_prop_id | acieve_fk | type | value |
+-----------------+-----------+----------------+-----------------+
| 1 | 1 | 1 | 'abc' |
| 2 | 2 | 1 | '145' |
+-----------------+-----------+-----------------+----------------+
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question