【问题标题】:php clicking on users name to display profilephp单击用户名以显示个人资料
【发布时间】:2021-10-30 06:32:57
【问题描述】:

所以我有这段代码来显示我的数据库中的所有用户并访问它们。这很好用,但是有什么方法可以到达它所说的点击这里只是为了在这种情况下显示一个变量领导名称(又名用户名)?

    <?php


require_once "config.php";
$sql = "SELECT id , leader_name, nation_name, power FROM nation_info";
$result = $link->query($sql);

if ($result->num_rows > 0) {
  // output data of each row
  while($row = $result->fetch_assoc()) {
   $nationList = [];
   $userid = $row['id'];

   echo ' <a href="viewnation.php?id=' . $userid . '">click here</a> '; // the click here on this line
   // echo '<a class="viewProfile" href="viewnation.php?id=' . $userid . '"><button>View Profile</button></a>'; old method of viewing profile
   echo "  Nation Name: " . $row["nation_name"]. "  Leader Name " . $row["leader_name"]. " Power " . $row["power"];
   
   echo "<br>";
  }
} else {
  echo "0 results";
}
$link->close();
?>

【问题讨论】:

    标签: php html mysql href


    【解决方案1】:

    你在说这个吗?只是打印名称而不是单击此处?

    <?php
    
    
    require_once "config.php";
    $sql = "SELECT id , leader_name, nation_name, power FROM nation_info";
    $result = $link->query($sql);
    
    if ($result->num_rows > 0) {
      // output data of each row
      while($row = $result->fetch_assoc()) {
       $nationList = [];
       $userid = $row['id'];
    
       echo ' <a href="viewnation.php?id=' . $userid . '">' . $row["leader_name"] . '</a> '; // the click here on this line
       // echo '<a class="viewProfile" href="viewnation.php?id=' . $userid . '"><button>View Profile</button></a>'; old method of viewing profile
       echo "  Nation Name: " . $row["nation_name"]. "  Leader Name " . $row["leader_name"]. " Power " . $row["power"];
       
       echo "<br>";
      }
    } else {
      echo "0 results";
    }
    $link->close();
    ?>
    

    【讨论】:

      猜你喜欢
      • 2016-06-26
      • 2021-03-09
      • 1970-01-01
      • 1970-01-01
      • 2016-04-28
      • 2019-06-30
      • 1970-01-01
      • 2021-09-04
      • 2020-12-14
      相关资源
      最近更新 更多