将 href 的 id 传入 href link

Pass the id of href into the href link

所以这是我的 problem.I 想要在 url 中打印动态获取的 href 的 id。 我的代码 category.php:

CATEGORY.PHP

while($row = mysql_fetch_assoc($result))
{   
    echo '<a id="' . $row['topic_id'] . '"  href="category.php?id=' . 
         $_SESSION['id'] . '&check1=//what should i put here?">;
}

我想要的只是让 check1 分别拥有每个 link 的 ID,所以如果我有 3 个 links(取决于数据库),第二个 link 将有 id =2,我想在下次加载 category.php 时打印 id=2。

但是

请注意,首先打印所有 id,然后有人会选择其中一个 link。

您已经在其他地方这样做了。 它被称为 concatenation - PHP 所做的一切都是动态生成的输出 HTML。这意味着在 echo 构造的引号内,您可以在任何地方连接。

您所要做的就是将其添加到 URL 中,就像您对 ID:

所做的那样
while ($row = mysql_fetch_assoc($result)) {
    echo '<a id="'. $row['topic_id'] .'" href="category.php?id='. $_SESSION['id'] .'&check1='. $row['topic_id'] .'"></a>'
}

你的 $row['topic_id'] 每次迭代都应该不同。 $row 变量设置为新的

这将输出与 link 的 id 属性相同的 $row['topic_id'] 但它还会将其作为 $_GET 参数附加到您的 category.php.

如果您不知道在 $_GET 数组中传递了什么,您总是可以在脚本的任何地方执行 print_r($_GET) 因为 $_GET 总是被设置(即使没有查询参数,它将只是空的)。

可能是我不清楚你在问什么,也可能是你想要实际的 primary key id 字段,在这种情况下你只需要交换最后一位:

&check1=$row['topic_id']

无论您的 ID 字段是什么名称,都可能类似于:

&check1=$row['id']

其中 id 是数据库中行的实际 id table。