Create a dynamic hyperlink inside a cell and send variable to another page – PHP

  php

Q(Question):

Hi
I have the following piece aof code

while($row = mysql_fetch_array($event))
{
echo "<tr>";
echo "<td>" . $row['surnameNM'] . "</td>";
$str_id = $row['personID'];
echo "<td>" . $row['nameNM'] . "</td>";
echo "<td>" . $row['personID'] . "</td>";
echo "</tr>";
}
mysql_close($getSurname);

I would like to create an hyperlink for each row on the NameNM field and send the corresponding personID within the hyperlink, something like getPerson.php?Identity=$str_id.

I have tried several options and none works. Please keep in mind it must be inside the "<td>" cell.

Thank you in advance

A(Answer):

Please use code tags when posting code.

There’s no hyperlink in your code.

A(Answer):

Exactly. I know how to do it in asp but not in PHP. I have tried several options but none works.

A(Answer):

You would have to show us one of the options you’ve tried before I can tell you where you went wrong.

A(Answer):

Here it goes
<a href="getPerson.php?identity=$str_id">Link to Page</a>
How do I place this inside
echo "<td>" . $row[‘nameNM’] . "</td>";
The variable $str_id is the personID of the nameNM I want.

A(Answer):

You can echo it like it is, you’ll just need to escape the double quotes.

A(Answer):

I am a complete newbie on PHP
Nevertheless i wrote
echo "<td><a href=getPerson.php?identity=$str_id>".$row[‘nameNM’]."</a></td>";
and it works.
Thank you for your didactical patience.

LEAVE A COMMENT