How can PHP developers efficiently handle duplicate entries in MySQL tables when displaying data?

When displaying data from MySQL tables in PHP, developers can efficiently handle duplicate entries by using the DISTINCT keyword in their SQL queries. This keyword ensures that only unique rows are returned, eliminating any duplicate entries from the result set.

<?php

// Connect to MySQL database
$mysqli = new mysqli("localhost", "username", "password", "database");

// Query to select distinct rows from a table
$query = "SELECT DISTINCT column1, column2 FROM table";

// Execute the query
$result = $mysqli->query($query);

// Display the data
while ($row = $result->fetch_assoc()) {
    echo $row['column1'] . " - " . $row['column2'] . "<br>";
}

// Close the connection
$mysqli->close();

?>