簡體   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