2011-08-24 38 views
-1

我开发了一个名为“profile.php”的php文件,显示当前用户的个人资料。但是,我无法决定如何显示他人的个人资料页面。我的意思是,例如,我在主页上显示了所有成员,并单击其中一个成员。然后,我应该为每个用户使用“a href”标签来指向另一个php文件,例如another_profile.php。如果是这样,我怎么能发送点击用户的信息,名称,姓氏等到another_profile.php? 谢谢显示其他用户的个人资料

+1

您应该首先从一些关于PHP的教程着手,特别是如何将参数传递给您的脚本。 – hakre

+0

不要认为它值得投票。 – rickyduck

回答

2

尝试GET变量...

<a href = "profile.php?profile_id=1">Check out the profile!</a> 

下一步赶上profile_id查询字符串$id = $_GET['profile_id']并找到id(第1是大小写)以获取属于该配置文件的数据。

我希望它有帮助。

0

不知何故,你的配置文件必须接受GET参数,例如id。这应该是您向数据库请求的ID,而不是当前用户的ID。

你的页面可能是这样的:

if(isset($_GET['id']) && is_numeric($_GET['id'])) //Is there an ID parameter, and is it numeric? 
    $id = $_GET['id']; //There was a user id in the url (profile.php?id=1) 
else 
    $id = $_SESSION['user_id']; //No id specified, get the current user's id. You need to change this to your own session key. 

然后用你的$id价值得到你需要的所有信息,例如:

$userInfo = mysql_query("SELECT firstname, lastname, etc, etc FROM user WHERE id = $id"); 
相关问题