-1

Is it possible to auto scroll to the bottom of a div container by implementing php codes?

I could not find any solution with pure css, however I found some solutions with javascript, the problem is that im learning PHP and do not plan to dive into javascript before sometime next year.

I currently have written this code:
note: I use: bootstrap, custom css, php and mysql.

<ul class="overflow-auto list-unstyled">
    <?php foreach($results as $value):
      if($value["person1"] == $user): ?>
        <li class="row p-3 m-2">
          <div class="col" style="width:70%">
          </div>
          <div class="col text-white text-center bg-primary p-3 chatBubbleUser">
            <?php echo $value["person1text"] ?>
          </div>
        </li>
      <?php endif;
      if($value["person1"] == $friend): ?>
        <li class="row p-3 m-2">
          <div class="col text-white text-center bg-success p-3 chatBubbleFriend">
          <?php echo $value["person1text"]; ?>
        </div>
        <div class="col" style="width:70%">
        </div>
        </li>
      <?php endif;
    endforeach; ?>
  </ul>

Custom CSS:

.chatBubbleFriend{


border-radius: 50px 50px 50px 5px; }

.chatBubbleUser{
  border-radius: 50px 50px 5px 50px; }

.col-lg-8{
  max-height: 500px;
  overflow-y: auto; }

is

Lajos Arpad
  • 64,414
  • 37
  • 100
  • 175
  • 2
    Does this answer your question? [What is the difference between client-side and server-side programming?](https://stackoverflow.com/questions/13840429/what-is-the-difference-between-client-side-and-server-side-programming) - Since PHP is a server side language, it can't change anything on the page once it left the server. – M. Eriksson Dec 15 '19 at 10:31
  • So since PHP is not a client-side language but a server-side language, it cannot manipulate the "looks" of the page? – Ole Kristian Dec 15 '19 at 10:49
  • Not more than outputting the initial page. To change the page after it has left the server and reached the client, you need to use Javascript to manipulate it. – M. Eriksson Dec 15 '19 at 11:13

1 Answers1

0

Not really. PHP runs on your server and the browser runs on your local computer. Scrolling is a ui event of your browser. PHP will not be able to tell your browser where to scroll.

You can issue commands from your server via push notifications and WebSocket to the browser of your users, but the browser must be able to interpret those commands and you will need some client-side coding to achieve this, most likely in Javascript.

Lajos Arpad
  • 64,414
  • 37
  • 100
  • 175