使用数据库中的user_id作为文件名创建动态php页面

Simple user post form which all works great but would like it to generate a php file that uses the user_id in the database. This way I can generate a link for that page to view the individual post. I am using fopen to create the page which also works.

How do I have it generate the 'user_id'.php as the new filename? You can see its naming the file 'newfile.php' currently.

// Create Post
session_start();
if(isset($_POST['createPostBtn'])){
  $myusername = $_SESSION['username'];
  $postTitle = $_POST['postTitle'];
  $postDesc = $_POST['postDesc'];
  $id = $row['user_id'];

  $myfile = fopen('newfile.php', 'w') or die("can't open file");

  $txt = "<?php include('init.inc.php'); ?>";
  $txt2 = "<?php include('header.php'); ?>";
  fwrite($myfile, $txt);
  fwrite($myfile, $txt2);
  fwrite($myfile, $myusername);
  fwrite($myfile, $id);
  fwrite($myfile, $postTitle);
  fwrite($myfile, $postDesc);
  fclose($myfile);

  mysql_query("INSERT INTO `users` (`post_title`, `post_description`, `username`) VALUES ('{$postTitle}', '{$postDesc}', '{$myusername}' )");   
}

Try the following code:

$id = '$row['user_id'].'.php'';
$myfile = fopen($id, 'w') or die("can't open file")

Ok so I figured this out, instead of creating the actual file I create it dynamically.

like this -

$forum .= '<div id="ptitle">' . '<a href=\mysite/thread.php?cid=' .$id . '>' . $ptitle.'</a>' . '</div>' ;

This creates the dynamic link..

$cid = $_GET['cid'];
$sql = "SELECT postid, username, post_title, post_description FROM post WHERE postid='".$cid."' LIMIT 1";
$res = mysql_query($sql) or die (mysql_error());
    if(mysql_num_rows($res) == 1) {
        $sql2 = "SELECT * FROM post WHERE postid='" . $cid. "'";
        $res2 = mysql_query($sql2) or die (mysql_error());
    if(mysql_num_rows($res2) > 0) {

    while ($row = mysql_fetch_assoc($res2)) {
        $myid = $row['postid']; 
        $myname = $row['username'];
        $mytitle = $row['post_title'];
        $mydesc = $row['post_description'];

        echo '<div id="mainCont">';
        echo '<div id="mainTitle">' . $mytitle . '</div>';
        echo '<div id="mainDesc">' . $mydesc . '</div>';
        echo '<div id="mainName">' . 'posted by: ' . $myname . '</div>';
        echo '</div>';
    }