Server-side languages are called first, before the page loads. Then the output of the server-side script is sent to the browser as HTML. If you view the page source, you'll see what I mean.
Everything else is done in top to bottom order then.
The only important thing to grasp is that while server-side scripts and client-side scripts are called from top to bottom, the server-side ones are done first on the server before the browser gets any content, and then the output of server-side scripts is sent to the browser to be executed.