如何导航到另一个页面并显示用户数据


How I can navigate to another page and display user data?

我知道如何使用下面的代码从数据库中获取用户数据。现在我想导航到另一个页面(使用onclick),并按id显示这些用户数据。这就像StackOverflow或Facebook一样,当你点击照片或id时,网站会将你带到用户的个人资料页面。

这是我到目前为止的代码:

  <?php
   $connect = mysql_connect("localhost","root","") or die(mysql_error());
   $select = mysql_select_db("profile") or die(mysql_error());
   $result = mysql_query("SELECT * FROM users order by id DESC");
   $id = $_SESSION['id'];
    while($row = mysql_fetch_array($result)){
        if($row['id'] !== $id){
             echo "<table id='suggest'><tr><td id='frienddata'><a href='http://localhost/profile/userprofile.php'>".$row['first'].' '. $row['last']."<a/></td><br></tr></table>";
        }
    }
?>

$id = $_GET['id'];
if(!isset($id))
{
$connect = mysql_connect("localhost","root","") or die(mysql_error());
   $select = mysql_select_db("profile") or die(mysql_error());
   $result = mysql_query("SELECT * FROM users WHERE id = '"$id"'");
if(!$result) 
{
  die('user_not_found');
}
mysqli_fetch_row( $result );
echo "<table id='sugest'><tr><td id='frienddata'><a href='http://localhost/profile/userprofile.php'>".$row['first'].' '. $row['last']."<a/></td><br></tr></table>";  

假设您在点击用户配置文件之前处于页面中,链接应该是类似于"site.com/userprofile.php?id=5'。现在在userprofile.php中:

$id = $_GET['id'];
if(!isset($id))
     die('user not found');
$connect = mysql_connect("localhost","root","") or die(mysql_error());
$select = mysql_select_db("profile") or die(mysql_error());
$result = mysql_query("SELECT * FROM users where id='".$id."'");
if (!$result) {
 die('user not found');
}
$row = mysql_fetch_row($result);
echo "<table id='sugest'><tr><td id='frienddata'><a href='http://localhost/profile/userprofile.php'>".$row['first'].' '. $row['last']."<a/></td><br></tr></table>";