You probably have to reverse your array/query to get the oldest messages at the top.
Also, in order to scroll to the bottom, you will need some form of Javascript. Do a search for "scrollTo" and you may find what you're looking for.
One of the more efficient ways of getting a simple chatroom up is for your main page to load all the relevant javascript functions to write to an output (chat) box with the properly formatted messages.
This way, all new lines of messages are appended to the end/bottom of the page via javascript (search: writeln, innerHTML). The overhead is much lesser in this case.
Cheers.
Alvin