【问题标题】:How to use the GET-method to get the id of the href that is clicked如何使用 GET 方法获取点击的 href 的 id
【发布时间】:2013-12-17 04:09:09
【问题描述】:


我想知道如何在我的 .php 文件中使用 GET 方法:forumdocument.php 来获取在 table.php
中单击的 href 的 ID 我希望这是开始它的正确方式:

'<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>";

【问题讨论】:

  • echo "&lt;td&gt;&lt;a class=\"formtitellink\" href=\"forumdocument.php\" id=\"" . $row['ID'] . "\"&gt;" . $row['Titel'] . "&lt;/a&gt;&lt;/td&gt;";

标签: php href getmethod


【解决方案1】:

GET 方法用于 url 中的名称值对。

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

在这里,如果我们使用$_GET['var1'],则预期值为var1

只需更改链接以反映所需的变量

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

然后您可以在forumdocument.php 上使用类似这样的东西来检索id

$rowid = $_GET['rowid'];

【讨论】:

    【解决方案2】:

    改变这部分

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

    【讨论】:

      猜你喜欢
      • 2011-07-27
      • 1970-01-01
      • 2018-11-12
      • 1970-01-01
      • 2011-12-11
      • 2019-02-22
      • 1970-01-01
      • 2013-03-06
      • 2022-07-19
      相关资源
      最近更新 更多