There are many links of the form

<a href="nameOfFile.php">name1</a> <a href="nameOfFile.php">name2</a> <a href="nameOfFile.php">name3</a> <a href="nameOfFile.php">name4</a> ..... 

These links are a table column and lead to the same file, which is a special form. I need in the file to which they lead (nameofFile.php) to get the name of the link (say name1), which I clicked on during the transition, in order to display the data on this name (name1). Tell me, please, how to implement it. I'm not familiar with js

The output of these links:

 for ($i = 0; $i < $fields=count($row); $i++) { if($i==0){ echo '<TD><a href="nameOfFile.php">' . $row[$i] . '</a></TD>'; } else{ echo '<TD>' . $row[$i] . '</TD>'; } } 
  • why don't you pass this same name as a parameter, so that the links would look like nameOfFile.php?name=name1 - Mike

1 answer 1

It is impossible to get the "link name" directly in the form in which you say (without JS at least). But nothing prevents you from adding another parameter to the links and passing through it the name:

 for ($i = 0; $i < $fields=count($row); $i++) { if($i==0){ echo '<TD><a href="nameOfFile.php?name=' . urlencode($row[$i]) . '">' . $row[$i] . '</a></TD>'; } echo { '<TD>' . $row[$i] . '</TD>'; } } 

And in nameOfFile.php you get this parameter in this way.

 $name = urldecode($_GET['name']); 
  • Thank you for such a prompt reply, but the fact is that I do not know in advance the name of the link. They are displayed through my array (I added the description in the question), what should I do in this case? - Maxim Petrov
  • And where are the link addresses themselves? in the code shown by you there are no links that will go to the .php-file - Ivan Pshenitsyn
  • <a href="nameOfFile.php"> '. $ row [$ i]. '</a> - Maxim Petrov
  • @MaximPetrov corrected the answer - Ivan Pshenitsyn