cjbeck71081 Posted August 13, 2007 Share Posted August 13, 2007 I have a zip code locator that i am writing script for and ive come across a problem. I have found a way to cross reference the LAT & LONG from a Zip Code table i have in my SQL datbase. I have another table that has the 25+ locations with thier LAT & LONG. I have managed to take the data from each of those tables and calculate distance with them, pull down specific information about the locations within a certain range of the users ZIP code. The problem i have is i need to be able to sort the information numerically. I thought the best way to do that is to populate a multidimensional array, then sort the array and "echo" the values of the array, wherever i needed them. However if there is a better way, im open to new ideas. Thanks in advance, im posting my code below. <? $zip = $_POST['zip']; $dis = $_POST['dis']; $con = mysql_connect($hostname,$username,$password); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db($dbName, $con); $query = "SELECT * FROM zip_code WHERE zip_code = '$zip'"; $result = mysql_query($query)or die ("Query Failed: $query - " . mysql_error()); $row = mysql_fetch_array($result); $lat1 = $row['lattitude']; $lon1 = $row['longitude']; $locquery = "SELECT * FROM locations"; $locresult = mysql_query($locquery)or die ("Query Failed: $query - " . mysql_error()); $myarray = array(); while($locrow = mysql_fetch_assoc($locresult)){ $lat2 = $locrow['loclat']; $lon2 = $locrow['loclon']; $myzip = $locrow['loczip']; $myadd = $locrow['locadd']; $myid = $locrow['locid']; $dist = acos(sin(deg2rad($lat1)) * sin(deg2rad($lat2)) + cos(deg2rad($lat1)) * cos(deg2rad($lat2)) * cos(deg2rad($lon1 - $lon2))); $dist = rad2deg($dist); $miles = (float) $dist * 60; if($miles < $dis){ $thisarray = ($miles = $myzip); array_push($myarray, $thisarray); echo($myadd." is ".$miles." from ".$zip."<br>"); } } ?> As you can probably see, the problem im having is that the array_push is not putting my values in properly. Anyway, any help is appreciated. Thanks Chris Link to comment https://forums.phpfreaks.com/topic/64599-sort-results-of-sql-or-populate-multidimensional-array-sort/ Share on other sites More sharing options...
cjbeck71081 Posted August 13, 2007 Author Share Posted August 13, 2007 Any ideas? Link to comment https://forums.phpfreaks.com/topic/64599-sort-results-of-sql-or-populate-multidimensional-array-sort/#findComment-322327 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.