php 如何使用GET方法获取被点击的href的id
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/20311557/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to use the GET-method to get the id of the href that is clicked
提问by Erwin
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:
我想知道如何在我的 .php 文件中使用 GET 方法:forumdocument.php 来获取在 table.php 中单击的 href 的 ID
我希望这是开始它的正确方法:
'<a class="formtitellink" href="forumdocument.php" id="$row['ID']">' . $row['Titel'] . '</a>' . "</td>";
table.php:
表.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>";
回答by James
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 idusing something like this on forumdocument.php
然后你可以使用检索id使用这样的东西forumdocument.php
$rowid = $_GET['rowid'];
回答by Ailton
Change this part
改变这部分
a class="formtitellink" href="forumdocument.php" id="$row['ID']"
a class="formtitellink" href="forumdocument.php"?id="'.$row['ID'].'"

