繁体   English   中英

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

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

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

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

  <?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>";  

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM