mysql fetch数组的问题[关闭]

I am using below code to loop records and display the Country value. If there are duplicate values they are all listed like Australia, Australia, United States, United States, United States. How can I remove any duplicates and just show Australia, United States? I cant use DISTINCT in mysql_query as I need to use an existing mysql_query. Thanks

<?php
while($row = mysql_fetch_array($result)) {
   echo $row['Country'];
}

?>

I cant use DISTINCT in mysql_query as I need to use an existing mysql_query.

I am using

$result = mysql_query("SELECT * FROM specials WHERE expiry > CURDATE() ORDER BY Country;") or die(mysql_error());

The best way to do this would be to use DISTINCT clause in your MySQL query:

SELECT DISTINCT Country FROM table_name

But however, since you added this:

I cant use DISTINCT in mysql_query as I need to use an existing mysql_query.

You can simply store all the countries in an array and then use PHP's built-in function array_unique() to remove the duplicate values, like so:

while($row = mysql_fetch_array($result)) {
    $countries[] = trim( $row['Country'] );
}
$countries = array_unique($countries);