Hi I will Explain what i want...
I have a table with records like this
...........................
country_name - username
India - abc1
Australia - abc2
India - abc3
USA - abc4
Australis - abc5
Lebanon - abc6
...........................
From Above Table I need to get country list without repeat, is there any chance to get like this...
Ex Code:
$sql = 'bla bla bla bla bla';
$res = mysql_query($sql);
while($row = mysql_fetch_array($res)){
echo $row['country_name'].'<br /><br />';
}
Ex Output(Like this):
India
Australia
USA
Lebanon
If is there any change to solve my issue please tell me and advance thanks for that!
Change your code to this -
$sql = "SELECT distinct country_name from my_table";
$res = mysql_query($sql);
while($row = mysql_fetch_array($res))
{
echo $row['country_name'].'<br /><br />';
}
From this link -
DISTINCT helps to eliminate duplicates. If a query returns a result that contains duplicate rows, you can remove duplicates to produce a result set in which every row is unique. To do this, include the keyword DISTINCT after SELECT and before the output column list.
Use DISTINCT:
$sql = "SELECT DISTINCT country_name FROM table";
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With