Page 1 of 1

How to stop fetching same data from database?

Posted: Fri May 15, 2009 9:27 am
by dinku33
I am retrieving states of USA on this page http://www.wewillbook.com/world-hotel-d ... tabase.php by using the below code. How to stop repeating the same state names. How can i do it?

Code: Select all

<?
$sql = "SELECT `State` FROM `citystatecountry` WHERE `Country` = 'USA' ORDER BY `State` ASC";
$result = mysql_query($sql);
while($row = mysql_fetch_assoc($result)){
echo $row['State'].'<br />';
}
?>

Re: How to stop fetching same data from database?

Posted: Fri May 15, 2009 9:40 am
by Benjamin

Code: Select all

SELECT DISTINCT `State` FROM `citystatecountry` WHERE `Country` = 'USA' ORDER BY `State` ASC

Re: How to stop fetching same data from database?

Posted: Wed May 20, 2009 12:26 pm
by dinku33
Thanks. It is working fine.