在我的网站上,我使用PHP中的echo显示了成员页面上的注册用户列表。我现在想将这些用户的姓名链接到他们的个人资料页面。有没有办法做到这一点?
我目前的代码:
<html>
<title>Find User Info</title>
<body>
<form method="POST">
<p>Type Username: </p><input type="text" name="username"placeholder="Enter Username...">
<br>
<input type="submit" name="submit" value="Search User">
</form>
<?php
session_start();
error_reporting(0);
$connection = mysql_connect("localhost", "root", "***"); // Establishing Connection with Server
$db = mysql_select_db("****", $connection); // Selecting Database from Server
$query = mysql_query("SELECT * FROM accs ORDER BY loginstatus"); //selecting all from table users where username is name that your is loged in
while($row = mysql_fetch_assoc($query))
{
echo $row['name'];
}
if(isset($_POST['submit'])){
$username = $_POST['username'];
$_SESSION['searchuser'] = $username; //setting session username to one from table, this is useful if you login, that restart your browser and than you go in url where is your profile.php... Anyway this is useful :D
header( 'Location: user.php' ) ;
}
?>
</body>
</html>
模板链接如下:mywebsite.com/search/user.php
答案 0 :(得分:2)
echo '<a href="link_to_profile.php">'.$row['name'].'</a>';
这就是你要找的东西吗?
答案 1 :(得分:1)
您需要做的就是使用适当的链接参数回显<a>
元素。
在循环中回显用户名称。您可以包含<a>
元素定义,并且只能将名称作为链接的文本:
while($row = mysql_fetch_assoc($query)) {
$user_name = $row['name'];
$profile_link = "http://your-cool-site/users/" . $row['id'];
echo "<a href='" . $profile_link . "' >" . $user_name . "</a>";
}
此代码假定您的用户页面的链接类似于:
http://your-cool-site/users/USER_ID