Read MySQL Database

I have a script that compares clicked latitude longitude to the nearest latitude longitude point in an array. The array is seen below. What is seen there is the id…and then the after array in order it is the cities forecast ID, latitude, longitude. This works fine however I have the same information stored in a MySQL database now. The rows are id …forecast_id …lat and lon. Is there anyway possible to get the MySQL row data and have it in the same form as the array below so that my script can compare the latitude longitude datas?

Any help would be great.

Thanks, Dave.

[php] $items = array(
‘0’ => array(‘s0000549’,‘43.24’,’-79.99’),
‘1’ => array(‘s0000692’,‘43.06’,’-79.11’),
‘2’ => array(‘s0000728’,‘44.57’,’-80.93’),
‘3’ => array(‘s0000571’,‘43.54’,’-80.23’)
);[/php]

My whole script is seen here.

[php]<?php

$lat = $_GET[“lat”];
$lon = $_GET[“lon”];

$ref = array($lat, $lon);

function distance($a, $B)
{
list($lat1, $lon1) = $a;
list($lat2, $lon2) = $b;

    $theta = $lon1 - $lon2;
    $dist = sin(deg2rad($lat1)) * sin(deg2rad($lat2)) +  cos(deg2rad($lat1)) * cos(deg2rad($lat2)) * cos(deg2rad($theta));
    $dist = acos($dist);
    $dist = rad2deg($dist);
    $miles = $dist * 60 * 1.1515;
    return $miles;

}
$items = array(
‘0’ => array(‘s0000549’,‘43.24’,’-79.99’),
‘1’ => array(‘s0000692’,‘43.06’,’-79.11’),
‘2’ => array(‘s0000728’,‘44.57’,’-80.93’),
‘3’ => array(‘s0000571’,‘43.54’,’-80.23’)
);

$distances = array_map(function($item) use($ref) {
$a = array_slice($item, -2);
return distance($a, $ref);
}, $items);

asort($distances);

$location = $items[key($distances)][0];

$url = ‘http://dd.weatheroffice.gc.ca/citypage_weather/xml/ON/’.$location.’_e.xml’;

$xml = simplexml_load_file($url);
$file_contents = file_get_contents($url);
$none = ‘’;

if(strpos($file_contents, $none) !== FALSE){

            echo 'NO WATCHES OR WARNINGS IN EFFECT';

}
else
{

foreach ($xml->warnings as $warning) {

$warntext = $warning->event->attributes()->description.’’;

echo $warntext;

     }

}

?> [/php]

Sponsor our Newsletter | Privacy Policy | Terms of Service