通过foreach循环点击链接时获取会话变量

时间:2012-05-21 20:13:28

标签: php database session

我正在尝试在单击链接时设置会话变量。 使用PHP从DB生成变量的值。我已经尝试了一切,但注意似乎有效。

有一个显示用户名的foreach循环。每个用户名都是指向第二页的链接。单击的用户名应成为会话变量。 循环的代码如下所示:

echo "<a href= 'nominate.php'> ".$myotherusers['username']. "</a><br/>";

目标是当点击链接时执行此代码:

$_SESSION['varname'] = $myotherusers['username'];

我似乎无法弄清楚如何...... 谢谢!

1 个答案:

答案 0 :(得分:1)

你可以这样做:

echo "<a href='nominate.php?user=".$myotherusers['username'].">".$myotherusers['username']."</a><br />";

然后在你的行动中:

$_SESSION['varname'] = $_GET['user'];