How to implement the function "Add to friends" in PHP? Scheme just throw in!
To begin with, think over the structure of the tables, it is obvious that there should be two tables, one with users, the second with friends. Many to many it is called. You create them, and in pkhp then you just take them to the table with your friends and add the id_user and id_drug. Id_druga is the same id_uzer from the table with users.
1st Table with users:
`users` `id` `name`
2nd Table connection with friends (I use. Many to many):
`friends` `user_id` `friend_id`
friend_id is the
id any user from the 1st table.
php business. For example
// берем ид-шник по имени поль-я $UserId = getUserIdByName($UserName); // берем ид-друга, так же само по его имени, $FriendId = getUserIdByName($FriendName); // Добавляем в таблицу friends связь function AddToFriend( $UserId, $FriendId );
Imagine that we have in the table with users two users
Вася  and
Петя , well, actually you  should also be there, i.e. 3 persons.
And we proceed further as I described above, first take your id, then id, say
Васи , and add them to the Friends table. What is the result?
You should end up with something like the following in the
`user_id` | `friend_id` 1 | 2
Петю , we act in the same way, take each other’s IDs and add them to the tab with friends, in the end we’ll get the following data set:
`user_id` | `friend_id` 1 | 2 1 | 3
Beautifully turned out? And now it's very easy to choose friends by your
id , but you do it first.
The scheme is simple: add a table in the database: friends with the fields id, user_id, friend_id Then you just write down the right people here