Ok with your code:
echo '<a href="test2.php?id=<?php print $myvariable; ?>>A function</a>';
a few pointers.firstly you do not need <?php print $variable;?> in an echo statement, eliminate this completely. try:
echo '<a href="test2.php?id=$myvariable>A function</a>';
next in HTML coding...