Jump to content

Recommended Posts

[move]PHP CODE[/move]

I have code
[code=php:0]
function inradius($zip,$radius)
    {
        global $db;
        $query="SELECT * FROM zipData WHERE zipcode='$zip'";
        $db->query($query);

        if($db->affected_rows()<>0) {
            $db->next_record();
            $lat=$db->f("lat");
            $lon=$db->f("lon");
            $query="SELECT zipcode FROM zipData WHERE (POW((69.1*(lon-\"$lon\")*cos($lat/57.3)),\"2\")+POW((69.1*(lat-\"$lat\")),\"2\"))<($radius*$radius) ";
            $db->query($query);
            if($db->affected_rows()<>0) {
                while($db->next_record()) {
                    $zipArray[$i]=$db->f("zipcode");
                    $i++;
                }
            }
        }else{
            return "Zip Code not found";
        }
    return $zipArray;
[/code]

where f is
[code=php:0]
  function f($Name) {
    return $this->Record[$Name];
  }
[/code]

I need for $zipArray[$i]=$db->f("zipcode"); to add another field.
So...

$zipArray[$i]=$db->f("zipcode"); <== puts 12345 into array
I have another funtion which stores distance. To call this function:
[code=php:0]
$distance = $zipLoc->distance($zipOne,$zipTwo);
[/code]

I want to add $distance in line with the zipcode, so that when I print out the array, I can sort by distance.
Link to comment
https://forums.phpfreaks.com/topic/27689-array-help/
Share on other sites

Why not just do it in query?

show me a few lines of your database and I will show you how to do the radius and sort by the miles and return the miles as decimal (00.00)

example... (what I want to see)

[code]INSERT INTO `us` VALUES (1, 'NY', '1', 'New York', 'Holtsville', 00501, 'N', 40.813061, 'W', -73.046371, 'Suffolk', 'C', '631', 'Eastern', 1, -5, 17006);
INSERT INTO `us` VALUES (2, 'NY', '1', 'New York', 'Holtsville', 00544, 'N', 40.813236, 'W', -73.049240, 'Suffolk', 'C', '631', 'Eastern', 1, -5, 17006);[/code]


printf
Link to comment
https://forums.phpfreaks.com/topic/27689-array-help/#findComment-126646
Share on other sites

If you want a copy of mine, I just updated it on Nov 10, just PM me and I will give you a CSV file or if you want a SQL dump, I'll give you that. This my data set, it very accurate compared to all the very bad pay for ones, the only pretty good pay for data set comes from GreatData.Com, but even theirs has many errors (relating to proper naming) in both the US and Canadian data sets...

If you want my set I'll give you an example using it, you can do both (driving and flying) miles, if not I will give you a simple example for your data!

printf
Link to comment
https://forums.phpfreaks.com/topic/27689-array-help/#findComment-126681
Share on other sites

Ok, just email me...

fataqui@gmail.com

Here is few examples that you can do with my dataset, I'll give you these scripts too!

// distance from 1 zip to another

http://zip.ya-right.com/distance/zip.php

// radius by zip code or city

http://zip.ya-right.com/distance/radius.php

// find the nearest post office from a given address

http://zip.ya-right.com/post/


Sonia

Link to comment
https://forums.phpfreaks.com/topic/27689-array-help/#findComment-126686
Share on other sites

I didn't forget you, I'll most likely will send you the data and scripts tomorrow. I just have not had much time to add comments throughout the code, I got most of it done, I just need to comment a zip class and the db class and I will send it to you. I wasn't planning on giving it out so I never commented it, now I have, so you will have it tomorrow...

printf
Link to comment
https://forums.phpfreaks.com/topic/27689-array-help/#findComment-128172
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.