How to stop fetching same data from database?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
dinku33
Forum Newbie
Posts: 10
Joined: Thu Jan 17, 2008 4:43 pm

How to stop fetching same data from database?

Post 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 />';
}
?>
User avatar
Benjamin
Site Administrator
Posts: 6935
Joined: Sun May 19, 2002 10:24 pm

Re: How to stop fetching same data from database?

Post by Benjamin »

Code: Select all

SELECT DISTINCT `State` FROM `citystatecountry` WHERE `Country` = 'USA' ORDER BY `State` ASC
dinku33
Forum Newbie
Posts: 10
Joined: Thu Jan 17, 2008 4:43 pm

Re: How to stop fetching same data from database?

Post by dinku33 »

Thanks. It is working fine.
Post Reply