I always put PHP first. By putting PHP first you're able to spew out error messages without messing up the HTML.
Take this for example.
PHP Code:
<?php function doerror($error) {
echo "<html>".
"<head></head>".
"<body>$error</body>".
"</html>";
exit;
}
$query = @mysql_query("SELECT * FROM table");
if (!$query) {
doerror("Query Failed");
}
$result = @mysql_fetch_array($query);
?>
<!-- Now your HTML page which uses the results -->
In this example, we do all of the PHP coding before the HTML, so we can check for errors, and if there are any, an error can be echoed out. This is considerably more difficult if your PHP code is integrated into the HTML.
PHP Code:
<html>
<head>
</head>
<body>
Welcome to the website. Please make a selection from the list below.
<?php $query = @mysql_query("SELECT * FROM table");
if (!$query) {
echo "There was an error";
exit;
}
$result = @mysql_fetch_array($query); ?>
</body>
</html>
As you can probably see, error checking here is done in a similar way, but echoing out errors isn't quite as tidy as in the first example.
And perhaps most importantly, in the first example, it's considerably easier to read the PHP code.
Bookmarks