How can PHP be used to display different sets of values from a database in different formats?

To display different sets of values from a database in different formats, you can use PHP to query the database and then format the results accordingly based on your requirements. You can use conditional statements or loops to iterate through the results and display them in the desired format. Additionally, you can use HTML and CSS to style the output as needed.

<?php
// Connect to the database
$servername = "localhost";
$username = "username";
$password = "password";
$dbname = "database";

$conn = new mysqli($servername, $username, $password, $dbname);

// Check connection
if ($conn->connect_error) {
    die("Connection failed: " . $conn->connect_error);
}

// Query the database for different sets of values
$sql = "SELECT * FROM table";
$result = $conn->query($sql);

// Display values in different formats
if ($result->num_rows > 0) {
    // Display values in a table format
    echo "<table>";
    while($row = $result->fetch_assoc()) {
        echo "<tr><td>" . $row["column1"] . "</td><td>" . $row["column2"] . "</td></tr>";
    }
    echo "</table>";

    // Display values in a list format
    echo "<ul>";
    while($row = $result->fetch_assoc()) {
        echo "<li>" . $row["column1"] . " - " . $row["column2"] . "</li>";
    }
    echo "</ul>";
} else {
    echo "0 results";
}

// Close the connection
$conn->close();
?>