Jump to content

DISTINCT not working


rmelino

Recommended Posts

Hello,

 

Hoping someone can help...

 

I am pulling records from a db of cities and state abbrevs.  My db has many duplicate city names but i want to echo out only the distinct ones.  My query is based on a radius around a city and i think this might be what is tripping up the DISTINCT mysql query.  Here is what i have:

	$teachradius = 50;
$add_under = array(" " => "_");
$query = sprintf("SELECT DISTINCT city, state_abbrev, ( 3959 * acos( cos( radians('%s') ) * cos( radians( lat ) ) * cos( radians( lng ) - radians('%s') ) + sin( radians('%s') ) * sin( radians( lat ) ) ) ) AS distance FROM cities HAVING distance < '%s' ORDER BY distance LIMIT 0 , 20",
  mysql_real_escape_string($lat_i),
  mysql_real_escape_string($lng_i),
  mysql_real_escape_string($lat_i),
  mysql_real_escape_string($teachradius));
$result = mysql_query($query);
while ($row = @mysql_fetch_assoc($result)){
echo '<li><a href="/' . strtolower($row['state_abbrev']) . '/' . strtolower(strtr($row['city'],$add_under)) . '.html">' . ucwords($row['city']) . ', ' . $row['state_abbrev'] . ' Dogs</a></li>',"\n";
}

 

Can you see what I might be doing incorrectly in my query so that i can echo out distinct city names / state abbrevs only?

 

Thanks in advance...

 

Link to comment
https://forums.phpfreaks.com/topic/231213-distinct-not-working/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.