What is the logic of follow and follow systems?

I’m thinking about some kind of project, and I’m thinking about a follower and the next system, for example twitter.I have a table of participants in the database. How can I make the system follow up. Why logic? I was working on something like this: I created a new table, the following name, and I have 3 rows. These lines are id, user_id, follower_id. is that enough for me? I do not know how to do that? Can you help me?

+5
source share
4 answers

Yes, such a design is sufficient for a simple next system such as Twitter. Of course, some additional data (for example, a timestamp, as suggested by @Ina) may be useful, and you do not need it id.

- :

userID INT PRIMARY,
followID INT PRIMARY,
creationTime DATETIME
+5

"" ( "" ) - , .

, , , , id.

user_id follower_id user FOREIGN KEY, , follower_id ( , ):

CREATE TABLE
        follows
        (
        user_id INT NOT NULL REFERENCES user (id),
        follower_id INT NOT NULL REFERENCES user (id),
        PRIMARY KEY
                (user_id, follower_id)
        KEY follower_id (follower_id)
        )
ENGINE=InnoDB -- if you want the foreign keys to work

.

, , :

CREATE TABLE
        follows
        (
        id INT NOT NULL PRIMARY KEY,
        user_id INT NOT NULL REFERENCES user (id),
        follower_id INT NOT NULL REFERENCES user (id),

        -- These are additional attributes

        follows_from DATETIME NOT NULL,
        follows_till DATETIME,

        --

        KEY follower_id (follower_id),
        KEY user_id (user_id)
        )
ENGINE=InnoDB -- if you want the foreign keys to work
+5

, People, " " People People. , PeopleID Following.

, Following. , PeopleID.

0

, , , : "friend1" "friend2" ( , ) "" "" ( ). PHP script, friend1 friend2 (, POST GET) . , -, AJAX PHP , HTML-, PHP .

0

All Articles