Skip to content
PHP Logo

How can dynamic links be generated in PHP for displaying member profiles on a website?

To generate dynamic links for displaying member profiles on a website in PHP, you can use URL parameters to pass the member's ID or username to a PHP script that retrieves and displays the corresponding profile information.

php
// Example PHP code to generate dynamic links for member profiles
// Assuming member IDs are stored in a database table called 'members'

// Displaying a list of member profiles with dynamic links
$query = "SELECT id, username FROM members";
$result = mysqli_query($conn, $query);

while ($row = mysqli_fetch_assoc($result)) {
    echo '<a href="profile.php?id=' . $row['id'] . '">' . $row['username'] . '</a><br>';
}

// Retrieving and displaying the member profile based on the ID passed in the URL
$member_id = $_GET['id'];
$query = "SELECT * FROM members WHERE id = $member_id";
$result = mysqli_query($conn, $query);
$member = mysqli_fetch_assoc($result);

echo 'Username: ' . $member['username'] . '<br>';
echo 'Email: ' . $member['email'] . '<br>';
// Display other profile information as needed