0

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 Answer 1

1

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'
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.