Skip to content
PHP Logo

How can one implement a link under each record in a PHP-generated list to access more detailed information about that specific record?

To implement a link under each record in a PHP-generated list to access more detailed information about that specific record, you can use a query parameter in the URL to identify the specific record being accessed. This way, when the link is clicked, the PHP script can retrieve the record based on the parameter and display the detailed information.

php
// Sample PHP code snippet to generate a list with links to detailed information

// Assuming $records is an array of records with details
foreach ($records as $record) {
    echo "<div>";
    echo "<p>{$record['name']}</p>";
    echo "<a href='detail.php?id={$record['id']}'>View Details</a>";
    echo "</div>";
}

// detail.php script to display detailed information based on the record ID
$recordId = $_GET['id']; // Retrieve the record ID from the query parameter
$record = // Retrieve the record details based on the ID from a database or other data source

// Display the detailed information
echo "<h1>{$record['name']}</h1>";
echo "<p>{$record['description']}</p>";