U
U
UnFox2018-06-02 02:52:15
MySQL
UnFox, 2018-06-02 02:52:15

How to get all chats that have a user?

There is a chats column in the database
e7OO7QLAp4U.jpg
, you need to get all the chats in which his id is mentioned by the user id (i.e. in users)

Answer the question

In order to leave comments, you need to log in

1 answer(s)
B
bkosun, 2018-06-02
@bkosun

More or less like this:

$users[] = 1; // ID пользователя

$q = "SELECT * FROM table regexp '(" . implode( '|', $users) . ")";

But I recommend reading about the normalization of relationships in the database and bring the structure of the current database to 3 normal form :
users
id, first_name, last_name, ...

chats
id, user_id, name, ...

chats_users
chat_id, user_id

UPD:
https://www.w3schools.com/sql/func_mysql_find_in_s...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question