0

JavaScript を使用した多くのソリューションを見てきましたが、HTML/CSS/PHP だけを使用してこれを実行しようとしています。

データベースからphpでコンテンツがロードされるテーブルがあり、スクロール可能にしました。今、スクロールを一番下から始めたいと思っています。

これが私のPHPです:

echo "<table>";
    //get messages
    $get_m = "select user_name, message, time from Chat NATURAL JOIN User where user_id = 1;";
   $messages = $db->query($get_m);
   //display messages

   foreach ($messages as $row) {
        //display each message in table
        echo "<tr>";
        echo "<td class='left'>" . $row['user_name'] . "</td>";
        echo "<td class='center'>" . $row['message'] . "</td>";
        echo "<td class='right'>" . $row['time'] . "</td>";
        echo "</tr>";
   }
        //end table
        echo "</table>";

これが私のCSSです:

#chat_tab table{
    position:               relative;
    display:                block;
    overflow-y:             scroll;
    scrollTop:              scrollHeight;
}

ありがとう!

4

1 に答える 1