Jump to content

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.