There are many PHP template scripts that have fancy ways to separate your "business code" from your "display code" (a common issue, and it sounds like this is what you want), but I usually just use PHP to do this, like so:
Business code:
$templateVars = array();
// prepare DB connection
$userRow = // retrieve the row
$templateVars['username'] = $row['name'];
$templateVars['email'] = $row['email'];
...
Display code:
<!-- insert fun table code for user profile page -->
<tr>
<td>Username:</td>
<td><?php echo $templateVars['username'] ?></td>
</tr>
<tr>
<td>Email:</td>
<td><?php echo $templateVars['email'] ?></td>
</tr>
...
This is a very basic example obviously... note that I use an array to give the template variables a different scope from the variables in my business code so they don't get mixed up. In the non-example world (that I assume you're coding in 🙂), this is more easily done with a template class. I can give you the one I use if you want, or you can choose from the many many template classes available on the internet.
But the point is this makes it easy to edit the page's HTML without having to look at the code for interacting with the database and such.
Btw good job for thinking of this, when I was a newbie and wrote my first BB system, ALL the code went together. 🙂 Not that you're a newbie.