How to create a php hyperlink with a variable?

maraesa1000

New member
I am trying to attach a variable extension to a hyperlink. I am trying to attach a variable called '$myvariable' to a URL

My hyperlink currently looks like this:

echo '<a href="test2.php?id=<?php print $myvariable; ?>>A function</a>';

I need it to be a PHP hyperlink as it is enclosed in a PHP 'while' loop. The hyperlink itself does works when outside of PHP tags (with the 'echo' removed) i just cant seem to get it to work!

Would hugely appreciate any suggestions!
if anyones curious how i did it, i enclosed each section of the URL into 'print' functions each on a seperate line on 3 lines.
 
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 standards when you adding values to properties in tags you need two ". one to open it, and one to close it. in the statement you only have one.. so in correction:

echo '<a href="test2.php?id=$myvariable">A function</a>';

when you want to use <?php print $variable... it would have to be in the HTML sections of the code:

<HTML>

<HEAD>
<TITLE><?php echo "New Title"; ?></title>
</HEAD>

<body>
<? php print $newvariable;?>
</body>
</HTML>
 
Back
Top