It is necessary to select data of two tables ( chat and users ). In this case, from the users table, I need a login field, which is indicated in the chat table as the user id in users. However, the SELECT * FROM chat LEFT JOIN users ON chat.author = users.id WHERE chat.room = номер комнаты ORDER BY chat.id array SELECT * FROM chat LEFT JOIN users ON chat.author = users.id WHERE chat.room = номер комнаты ORDER BY chat.id returns
Array ( [0] => Array ( [id] => 1 [ctime] => 1468691947 [author] => 1 [title] => [room] => 1 [message] => 11111 [login] => admin [password] => 1683bed6dd5702c3a6a5982da26ee19e [reg_time] => 1468669491 [real_name] => Serhiy [about] => i am not in danger! i am the danger! [email] => milo@sobaka.lomaka [active] => 1 [role] => 1 ) [1] => Array ( [id] => 1 [ctime] => 1468691942 [author] => 1 [title] => [room] => 1 [message] => asdasdasd [login] => admin [password] => 1683bed6dd5702c3a6a5982da26ee19e [reg_time] => 1468669491 [real_name] => Serhiy [about] => i am not in danger! i am the danger! [email] => milo@sobaka.lomaka [active] => 1 [role] => 1 )` In this case, it is necessary that the id array was not the author of the message, but the message. Help make a request