Jump to content

Finding the right array number from a zip code


dani33l_87
Go to solution Solved by ginerjm,

Recommended Posts

I have build a small form that take the zip code that user enter and if is on my list will redirect to a sub domain craigslist.

 

I was checking all the zip codes and is pretty hard to know to what bigger city to attribute the  given zip code and for that I was thinking to a simple idea to use, I am not sure how much exact will be but I think will do the trick for the moment.

 

The zip code range start from  00501 to 99950. 

 

I create a array with the biggest city shown in craigslist and the zip code that correspond. 

 

Now the tricky part, what I will do with the rest of the zip codes and my idea is to measure the distance from one to another zip code and which zip code from the array is closer from given one  to take it.

<?php 

$zip = $_GET['zip']; 


    $z = array (
36830 => array ( 'auburn.craigslist.org' ),
35242 => array ( 'bham.craigslist.org' ),
36301 => array ( 'dothan.craigslist.org' ),
35630 => array ( 'shoals.craigslist.org' ),
35901 => array ( 'gadsden.craigslist.org' )


?>




Exemple:

$zip= 36870 // the code received from the user

36870 - $array=  ( 'auburn.craigslist.org' ),
           (36830  = 40)
           (36301 = 569)
           (36911 = -41)  // the minus will be excluded
           (....etc)

After checking the zip code with  the ones from array, the smaller score will attribute the sub-domain  correspond from the array. I hope will don  t be the case when will get  the same result from two zip codes:)

 

 

Now I am using this rule:

$zip0 = (isset($z[$zip][0]) && $z[$zip][0] != '') ? $z[$zip][0] : 'craigslist.org/about/sites#US';

and I was thinking to redirect the user for a page to enter the state and the city. But I wish to make it more precises and not to involved the user so much.

 

 

But if there are any other suggestions I will be glad to hear them.

Edited by Zane
Link to comment
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.