使用php内的链接

I am unable to concatenate HERE it would be great if somebody can point out my mistake and let me know what I am doing wrong and how it should be done.

<?php
.
.
while ($query_row = mysql_fetch_assoc($query_run)){             

$id=$query_row['id'];
$firstname=$query_row['firstname'];

echo '<a class="profile" href="profile.php?id=<?php echo $id.' ">'ucfirst' ($firstname);?></a>'; // HERE
.
.
.       
?>

You are in a <?php (line 1), so you can't use an other tag inside it (in your echo). It should look this way :

echo '<a class="profile" href="profile.php?id='.$id.'">'.ucfirst($firstname).'</a>';

You use php tag inside php tag without close it and your ucfirst treated as a string.

echo '<a class="profile" href="profile.php?id='.$id.'">'.ucfirst($firstname).'</a>'; // HERE

Note:- mysql is deprecated instead use mysqli or pdo