How can PHP be utilized to handle and display multiple records from a database in a structured format?

To handle and display multiple records from a database in a structured format using PHP, you can fetch the records from the database using SQL queries, store them in an array, and then iterate through the array to display each record in a structured format on the webpage.

<?php
// Connect to the database
$connection = mysqli_connect("localhost", "username", "password", "database");

// Check connection
if (!$connection) {
    die("Connection failed: " . mysqli_connect_error());
}

// Fetch records from the database
$sql = "SELECT * FROM table_name";
$result = mysqli_query($connection, $sql);

// Display records in a structured format
if (mysqli_num_rows($result) > 0) {
    while($row = mysqli_fetch_assoc($result)) {
        echo "ID: " . $row["id"] . " - Name: " . $row["name"] . "<br>";
    }
} else {
    echo "0 results";
}

// Close database connection
mysqli_close($connection);
?>