Hello, there is a question, I have a working chat on PHP and a database on one of the sites, but it is updated only when the page is reloaded, I don’t have Ajax, I want to implement it, but I don’t know how, I figured it out with ajax itself, but I don’t have any idea how to use it, insert the chat php code, tell me how to update the messages without reloading, it is possible to redo the code, it is possible to track a new message in the database, and then run Ajax, I don’t know if you write the code, I will appreciate it.
<?php if (isset($_SESSION['loggeduser']) and $_SESSION['loggeduser']['ban status'] <= 0) { //Берём сообщения с БД $messages = mysqli_query($connection, "SELECT * FROM `chat`"); while ($message = mysqli_fetch_assoc($messages)) { //Пока $messages не опустеет, превращаем в строки, и выводим сообщение в отдельном блоке $messageId = $message['id']; $authorInfo = mysqli_query($connection, "SELECT * FROM `users` WHERE `id` = '".$message['author_id']."' "); $author = mysqli_fetch_assoc($authorInfo); ?> //Пока $authorInfo не опустеет, превращаем в строки, и выводим аву и логин автора сообщения <div class="message row" id="<?php echo $message['id']?>"> <div class="col-xs-2 col-sm-2 col-md-2 col-lg-2 messageLeftPart"> <!--Аватарка автора сообщения в виде фона блока, остальные стили в файле стилей--> <div class="authorAvatar" style="background-image: url(../images/uploaded/avatars/<?php if (empty($author['avatar'])){echo 'default.png';} elseif (!empty($author['avatar'])){echo $author['avatar'];} ?>);"></div> </div> <div class="messageTextAndLogin col-xs-10 col-sm-10 col-md-10 col-lg-10"> <!--Выводим логин автора в виде ссылки сразу на его профиль--> <h4 class="authorLogin"><a href="profile.php?id=<?php echo $author['id']?>"><?php echo $author['login'];?></a></h4> <!--Выводим время отравки сообщения--> <p class="messageTime"><?php echo $message['time']?></p> <!--Выводим текст сообщения--> <p class="messageText"><?php echo $message['text'];?></p> </div> </div>