FROM (SELECT name, text, date FROM replies
UNION SELECT name, text, date FROM supportmessage)t ORDER BY date");
$arr = [];
while($row = mysqli_fetch_assoc($res)){
$arr[] = $row;
}
return $arr;
}
View:
<?foreach($replies as $reply){
if($reply['name']=="admin"){
?>
<!-- Message. Default to the left -->
<div class="direct-chat-msg">
<div class="direct-chat-infos clearfix">
<span class="direct-chat-name float-left"><?=$reply['name']?></span>
<span class="direct-chat-timestamp float-right"><?=$reply['date']?></span>
</div>
<!-- /.direct-chat-infos -->
<img class="direct-chat-img" src="<?=THEME?>dist/img/user1-128x128.jpg" alt="message user image">
<!-- /.direct-chat-img -->
<div class="direct-chat-text">
<?=$reply['text']?>
</div>
<!-- /.direct-chat-text -->
</div>
<!-- /.direct-chat-msg -->
<?}else{?>
<!-- Message to the right -->
<div class="direct-chat-msg right">
<div class="direct-chat-infos clearfix">
<span class="direct-chat-name float-right"><?=$reply['name']?></span>
<span class="direct-chat-timestamp float-left"><?=$reply['date']?></span>
</div>
<!-- /.direct-chat-infos -->
<img class="direct-chat-img" src="<?=THEME?>dist/img/user3-128x128.jpg" alt="message user image">
<!-- /.direct-chat-img -->
<div class="direct-chat-text">
<?=$reply['text']?>
</div>
<!-- /.direct-chat-text -->
</div>
<!-- /.direct-chat-msg -->
<?}}?>
Mysql:
CREATE TABLE replies (
id int NOT NULL,
name varchar(255) NOT NULL,
text text CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL,
user_id int NOT NULL,
date datetime NOT NULL DEFAULT CURRENT_TIMESTAMP
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
--
-- Дамп данных таблицы replies
--
INSERT INTO replies (id, name, text, user_id, date) VALUES
(1, 'admin', 'I dont know', 1, '2022-01-19 19:33:00'),
(2, 'admin', 'You can read manual', 2, '2022-01-21 19:33:58'),
(3, 'admin', 'Hello! We are learning the problem', 3, '2022-01-23 19:32:58');
CREATE TABLE supportmessage (
id int NOT NULL,
name varchar(255) NOT NULL,
question varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci DEFAULT NULL,
text text NOT NULL,
item_id int NOT NULL,
date datetime DEFAULT CURRENT_TIMESTAMP
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
--
-- Дамп данных таблицы supportmessage
--
INSERT INTO supportmessage (id, name, question, text, item_id, date) VALUES
(1, 'akmal', 'Проблемы с кабинетом', 'Проблемы с кабинетом', 5, '2022-01-18 15:29:32'),
(2, 'oleg', 'Проблемы с оплатой', 'Да все равно', 11, '2022-01-20 15:29:42'),
(3, 'bobur', 'Проблемы с кабинетом', 'Плохо и хуже не бывает', 5, '2022-01-22 15:50:24');
CREATE TABLE users (
id int UNSIGNED NOT NULL,
name varchar(255) NOT NULL,
email varchar(255) NOT NULL,
password varchar(255) NOT NULL,
img varchar(255) DEFAULT NULL,
isAdmin int DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
--
-- Дамп данных таблицы users
--
INSERT INTO users (id, name, email, password, img, isAdmin) VALUES
(1, 'bobur', 'admin@mail.ru', 'admin', '02.jpg', NULL),
(2, 'akmal', 'admin@mail.ru', 'admin', '02.jpg', 1),
(3, 'oleg', 'oleg@mail.ru', '1234', '2.jpg', 0);
pastebin и прочее, не нужно простыню кода сюда писать.
Обсуждают сегодня