You are here: Re: Is This Possible? « PHP SQL « IT news, forums, messages
Re: Is This Possible?

Posted by J.O. Aho on 11/03/06 06:02

Tyrone Slothrop wrote:
> I need to write a query which will find those records which have the
> closest values to a zip code posted through a form. The values may be
> greater than or less than the requested value.
>
> I had written a function which accomplishes this which uses multiple
> queries many years ago. As I am now revising the site in a major
> redesign, the thought occurred to me that there must be a better way.
>
> Any ideas?

If you have number only zip codes (not all countries has that), then you can
use a simple interval limitation (as numbers close to another usually are
close in geographical terms too, but not always true).


$query="SELECT * FROM ZipTable WHERE (ZipCode > $ZipNumber - $Range) AND
(ZipCode < $ZipNumber + $Range)";

Where we use two variables set by the php-script, $ZipNumber is the zip code
we are searching for and $Range is the value how much larger or smaller the
zip code is for those which are "near".

It's of course a question how you determine what is close, so this simple
query may not be what you was looking for.



//Aho

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация