简体   繁体   English

如何使用GET方法获取被点击的href的ID

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


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 我想知道如何在.php文件:forumdocument.php中使用GET方法来获取在table.php中单击的href的ID。
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: 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>";

A GET method is used for name value pairs in a url. GET方法用于url中的名称/值对。

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

Here if we use $_GET['var1'] the expected value would be var1 . 在这里,如果我们使用$_GET['var1']则期望值为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 然后,您可以在forumdocument.php上使用类似这样的方式检索id

$rowid = $_GET['rowid'];

Change this part 改变这部分

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

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM