Forum Moderators: coopster

Message Too Old, No Replies

Comparing and removing duplicate entries

         

maccas

5:57 pm on Sep 27, 2005 (gmt 0)

10+ Year Member



Hi, I have a map of the UK and when someone types in a town I select the postcode (1st part) and the postcodes corresponding latitude and longitude values and plot it to the map. Now I am trying to remove entries that are close to each other as the text I am putting on the map sometimes overlaps. So on the below code where $latitude and $longitude are within a certain distance from each other, say 1 for latitude and .5 for longitude I want to remove them all except for one. I can GROUP BY County but there are some towns with the same name that are in the same county. Any ideas?

$result = mysql_query("SELECT * FROM postcode_names JOIN postcode_data ON postcode_names.postcode=postcode_data.postcode WHERE town = '$town'") or die(mysql_error());
while($row = mysql_fetch_array( $result )) {
$county =$row['county'];
$latitude = $row['lat'];
$longitude = $row['long'];

coopster

9:58 pm on Sep 27, 2005 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



How about a bigger map? ;)

But seriously, are those options something you have considered? Maybe you could display the data in a different fashion with an image map and rollover points? Or have you already considered alternatives such as this and decided that you really need to trim down the result set being returned?

maccas

10:20 pm on Sep 27, 2005 (gmt 0)

10+ Year Member



Yeah I was thinking of either that or have a number key at the site and just put the numbers besides the dots on the map.

coopster

1:15 pm on Sep 28, 2005 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Well if you do decide to trim down the result set you would obviously have to compare entries to each other -- which is going to be easier to do after the result set is returned in my humble opinion. To retrieve data based on a constant variable is one thing, to retrieve data based on row-comparisons is whole new ball game. Not that you can't do it, but it gets more complex -- the technique often involves temporary tables or self joins. In this particular instance you may be better off just analyzing information as you loop through the result set and determine whether or not you want to include it in your information display.