What alternative methods can be used to avoid duplicate entries when fetching and displaying data from a MySQL database in PHP?

When fetching and displaying data from a MySQL database in PHP, one way to avoid duplicate entries is to use the DISTINCT keyword in your SQL query. This will ensure that only unique records are returned. Another method is to store the retrieved data in an array and use the array_unique() function to remove any duplicate entries before displaying them.

// Using DISTINCT keyword in SQL query
$sql = "SELECT DISTINCT column_name FROM table_name";
$result = mysqli_query($conn, $sql);

// Storing data in an array and removing duplicates
$data = array();
while ($row = mysqli_fetch_assoc($result)) {
    $data[] = $row['column_name'];
}

$data = array_unique($data);

// Displaying the unique data
foreach ($data as $value) {
    echo $value . "<br>";
}