There was such a question: how to make the user stay on the place where he was when writing, for example, a comment when reloading the page? those. when writing a comment, and sending it, I constantly reload the page, and I find myself at the very top of the site, but I need to stay where I wrote the comment.

session_start(); include_once("settings.php"); $sql = sprintf("SELECT comment_text FROM comments WHERE id_post = '$post' ORDER BY id_comment"); $result = mysqli_query($connection, $sql); while($row = mysqli_fetch_assoc($result)){ echo '<div class = "row comment pt-2"><div class = "col-md-1"><img class = "avatar" src = "../assets/images/user.png"></div><div class = "comment col-md-11">'. $row['comment_text'].'</div></div>'; } 
  • just use ajax - madfan41k

1 answer 1

the simplest option: wrapping comments in a div with an id attribute, for example

 <div id="comments"> ... здесь твои комментарии </div> 

On the form as an action you specify an address with an anchor, for example

 <form action="/post.php#comments"> ... тело формы </form> 

When the browser receives a URL with an anchor (# ...), it searches for an item on the page with such an id and scrolls to it.

Another option, if you master JavaScript, you can send a request to the server without rebooting using AJAX.

  • And how can this be done through jqury? Sorry for such possibly stupid questions, I just don’t understand js ... - Wart Vader