How can PHP be used to optimize the display of data from a MySQL table on a smartphone?

To optimize the display of data from a MySQL table on a smartphone, you can use PHP to fetch the data from the database and format it in a responsive way that fits the smaller screen size of a smartphone. This can be achieved by using CSS media queries to adjust the layout and styling based on the device's screen size.

<?php
// Connect to MySQL 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);
}

// Fetch data from MySQL table
$sql = "SELECT * FROM table_name";
$result = $conn->query($sql);

// Display data in a responsive way for smartphones
if ($result->num_rows > 0) {
    while($row = $result->fetch_assoc()) {
        echo "<div class='data'>";
        echo "<p>Name: " . $row["name"] . "</p>";
        echo "<p>Email: " . $row["email"] . "</p>";
        echo "<p>Phone: " . $row["phone"] . "</p>";
        echo "</div>";
    }
} else {
    echo "0 results";
}

$conn->close();
?>