Associate variable ID with profile page
P粉022285768
P粉022285768 2023-09-10 10:56:31
0
1
495

I have a page that displays some information from the database. I want to add a link to each row (say the name as a link) that I can click to jump to a page that displays the rest of the information for that row (say a profile page). I thought about creating a link that passes the id to the profile page so the profile page can get the information.

I'm sure this is simple, but I just don't get it. How can I display a link in each row that only sends the id number of that row? Because I don't want to go to each row and create a special link.

Here is the code I have:

<?php
$servername = "localhost";
$username = "username";
$password = "password";
$dbname = "myDB";

// 创建连接
$conn = new mysqli($servername, $username, $password, $dbname);

// 检查连接
if ($conn->connect_error) {
  die("连接失败: " . $conn->connect_error);
}


$sql = "SELECT id, FirstName, LastName, Phone, Email FROM Contacts";
$result = $conn->query($sql);

if ($result->num_rows > 0) {
  // 输出每一行的数据
  while($row = $result->fetch_assoc()) {
    echo "id: " . $row["id"]. " - Name: " . $row["FirstName"]. " " . $row["LastName"]. " " . $row["Phone"]. " " . $row["Email"]. "
"; } } else { echo "0 结果"; } $conn->close(); ?>```

P粉022285768
P粉022285768

reply all(1)
P粉998100648

Based on your example, you can do this:

connect_error) {
    die("连接失败: " . $conn->connect_error);
}


$sql = "SELECT id, FirstName, LastName, Phone, Email FROM Contacts";
$result = $conn->query($sql);

if ($result->num_rows > 0) {
    // 输出每行数据
    while ($row = $result->fetch_assoc()) {
        echo "id: " . $row["id"] . " - Name: 
            
            
            
            
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!