Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to implement a friendship system in my database?
    primarykey
    data
    text
    <p>I have a user system in my database and I want to adding the posibility of add friends. The user have to be able to: </p> <ul> <li>Send a message in the petition </li> <li>Block user </li> <li>Set alias to friend user.</li> </ul> <p>So I though this table:</p> <pre><code>id_friend id_user1 id_user2 id_user_sender alias_user1 NULL alias user2 NULL status message NULL date_sent date_accepted NULL </code></pre> <p>I'm going to explain each colum:</p> <ul> <li><strong>id_friend</strong>: PK of the table.</li> <li><strong>id_user1</strong>: FK of users table</li> <li><strong>id_user2</strong>: FK of users table</li> <li><strong>id_user_sender</strong>: the id_user of who send the petition</li> <li><strong>alias_user1</strong> NULL: the alias seted by id_user1 to id_user2 (optional)</li> <li><strong>alias user2</strong> NULL: the alias seted by id_user2 to id_user1 (optional)</li> <li><strong>status</strong> : if 0 friendship pendient. if 1 friends. if 2 friendship bloqued.</li> <li><strong>message</strong> NULL: if status = 0 then can contain a message seted by the sender</li> <li><strong>date_sent</strong>: date when sender sent the petition</li> <li><strong>date_accepted</strong> NULL: date when user_requested acepted the friendship.</li> </ul> <p>Then to get all the friends of a specific user I'll do:</p> <pre><code>select id_user1, id_user2 from friends where id_user1 = $my_user_id or id_user2 = $my_user_id and status = 1; </code></pre> <p>Then I'd discard the id_users equal to mine, so the result contains only the user who are my friends. But to get the alias I don't have any idea. May be with more tables?</p> <p>I think I'm designing it wrong... Do you have any tip or advice? could you give some example please?</p> <p>If you need more info let me know and I'll edit the post.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload