I will put the large part of php tasks, such as get from database, insert database, calculation, assign values etc. before <html></html>, and then between <html></html>, mostly I will insert the php codes into html tags like this
<?php
//all the possible tasks that can be done first.
// assign the results into array or variables to display later on in the html page
?>
<html>
<body>
<?php
//for example i will either display the results or display a form
if (...) // this is decided in the previous php codes blocks.
{
?>
<table>
<tr>
<td>
<?php echo ($results1); ?>
</td>
</tr>
</table>
<?php
}
else
{
?>
<form>
...
</form>
<?php
}
?>
</body>
</html>
In simple words, I would put the most php programming codes in a <?php ?> block, and assign the result values to variable or array before <html></html>
and then use the <?php echo($variable); ?> and these if, for, while loop of php codes around html tags or embedded into html tags to pass the values into <html></html> to create a web page.
When html and php tags/codes merge together. I either put the php codes around the html tags. such as
if (...) // this is decided in the previous php codes blocks.
{
?>
<table>
<tr>
<td>
Welcome back! David.
</td>
</tr>
</table>
<?php
}
?>
Or embed php codes into html tags such as
<table>
<tr>
<td>
<?php echo ($results1); ?>
</td>
</tr>
</table>
This way, a graphical desinger open the page in dreamweaver etc. He can see the page almost as a pure html page. except some place repace the text with <?php echo(...); ?> php codes.