dooberrydan, I do not suggest you use fopen and fwrite. You will only need those if you intend to convert the data into HTML and save the HTML file permanently.
Since the whole point of your project is to build the HTML dynamically from the database, there will be no need to save the HTML since the data remains in the database.
Let's assume that you have three fields in your database. Name, City, and State. As you can see from the following example, the script reaches into the database, reads the fields, and displays the page. There is no need to then WRITE that page to the hard drive with fwrite or fopen.
<?
mysql_connect("localhost","username","password");
@mysql_select_db("databasename") or die( "Unable to select database");
$id = $_REQUEST['id'];
$query = "select name,city,state from customers where id=$id";
$result = MYSQL_QUERY($query);
list($name,$city,$state) = @mysql_fetch_row($result);
?>
<html>
<head>
<title>This is the page for <?php print "$name"; ?></title>
</head>
<body>
<center>
<h1>Welcome to <?php print "$name"; ?>'s page</h1>
</center>
<?php print "$name"; ?> is from <?php print "$city"; ?> which is in the lovely state of <i><?php print "$state"; ?></i>
</body>
</html>