How to use the GET-method to get the id of the href that is clicked

25.5k views Asked by At


I would like to know how I can use the GET-method in my .php file: forumdocument.php to get the ID of the href that is clicked in table.php
I hope this is the right way to begin it:

'<a class="formtitellink" href="forumdocument.php" id="$row['ID']">' . $row['Titel'] . '</a>' . "</td>";

table.php:

$query = "Select *
        from forum";
$resultaat = mysql_query($query, $connectie);
echo "<table border='1'>
<tr>
<th>ID</th>
<th>Tijd</th>
<th>Gebruikersnaam</th>
<th>Titel</th>
</tr>";

while($row = mysql_fetch_array($resultaat))
  {
  $_SESSION['row'] = $row;
  echo "<tr>";
  echo "<td>" . $row['Tijd'] . "</td>";
  echo "<td>" . $row['Gebruikersnaam'] . "</td>";
  echo "<td>" . '<a class="formtitellink" href="forumdocument.php" id="$row['ID']">' . $row['Titel'] . '</a>' . "</td>";
  echo "</tr>";
  }
echo "</table>";
2

There are 2 answers

0
James On BEST ANSWER

A GET method is used for name value pairs in a url.

Example: www.test.com?var1=var1&var2=var2

Here if we use $_GET['var1'] the expected value would be var1.

Just change your links to reflect the desired variable

href="forumdocument.php?rowid=".$row['ID']."

Then you can use retrieve the id using something like this on forumdocument.php

$rowid = $_GET['rowid'];
0
Ailton On

Change this part

a class="formtitellink" href="forumdocument.php" id="$row['ID']"    

a class="formtitellink" href="forumdocument.php"?id="'.$row['ID'].'"