How can PHP be used to retrieve data from a MySQL table and manipulate it for specific output requirements?

To retrieve data from a MySQL table and manipulate it for specific output requirements, you can use PHP in conjunction with MySQL queries. You can fetch the data from the table using SELECT queries, manipulate it using PHP functions, and then output the data in the desired format.

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

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

// Fetch data from MySQL table
$query = "SELECT * FROM table_name";
$result = mysqli_query($connection, $query);

// Manipulate data and output in desired format
if (mysqli_num_rows($result) > 0) {
    while ($row = mysqli_fetch_assoc($result)) {
        // Manipulate data here
        echo "ID: " . $row['id'] . " - Name: " . $row['name'] . "<br>";
    }
} else {
    echo "No results found";
}

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