I
I
Ilya2014-10-18 18:52:11
PHP
Ilya, 2014-10-18 18:52:11

How to implement database structure?

Good time. I'm writing a chat. Faced the problem of implementing rooms in the chat.
Now such structure db:
2014-10-18_19-49-08.png
And a problem such. Can't figure out how to link two users to the chats table? So that, for example, when logging into your account, the user sees his rooms.
I hope you understood what I meant.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
D
Dmitry Entelis, 2014-10-18
@ArtMavir

This is called a many-to-many ratio.
It is set by a separate plate of the form

CREATE TABLE `xref_user_chat` (
 `user_id` int(11) NOT NULL,
 `chat_id` int(11) NOT NULL,
 PRIMARY KEY (`user_id`,`chat_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8

B
Be Joy, 2014-10-18
@bejoy

Do you need the owner to view the objects he owns?
In the `chats` table, enter the owner account handle field.
Show owner its objects WHERE chat owner account handle = current account handle.
Which two users should be associated with the `chats` table?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question