views:

15

answers:

1

I have this query that searches my database for accommodation that has a type that is equal to e.g. "Hotel" it then outputs the results in an list displaying the location of the hotels. Basically because there are lets say 4 hotels in Windermere, Windermere is coming up 4 times. Is there anyway I can tell it to only display one instance of one value? Thanks in advance

<?php

include $_SERVER['DOCUMENT_ROOT']."/include/dbcon.php";
$query = "SELECT * FROM Places WHERE Type ='$type'" or die(mysql_error()); 
$result = mysql_query($query) or die(mysql_error());
echo "<ul>";
while ($row = mysql_fetch_array($result)) {

$link = $row ['Location'];
$link = strtolower($link);
$link = str_replace(" ", "-", $link);
$link = str_replace(".-", "-", $link);

echo "<li>";
echo "<a href='".$link."/"."'>".$row['Location']."</a>";
echo "</li>";
}
echo "</ul>";
mysql_close($con);
?>
+1  A: 

In your SQL you can use a GROUP BY statement:

SELECT Location FROM Places WHERE Type ='$type' GROUP_BY Location

Another possibility is using DISTINCT:

SELECT DISTINCT(Location) FROM Places WHERE Type ='$type'
captaintokyo
excellent, thank you
AJFMEDIA