Page 1 of 1
need help on associative table
Posted: Mon Apr 05, 2004 8:55 pm
by bugthefixer
i need to enter more then 600 cities and their distance from each other..i cant figure out the structure of the table how it shud look like..kan anybody tell me about tat...
Posted: Mon Apr 05, 2004 9:32 pm
by Ixplodestuff8
Store the x,y co-ordinates in the table (chances are Latitude and Longitude ) Then have the php script do the math to find the distance between two co-ordinates.
use the distance formula:
edit: I had an image with the distance formula there, but the website didn't let the image be linked to from the forum.
gimme some kind of code
Posted: Mon Apr 05, 2004 9:49 pm
by bugthefixer
may be u r right but kan u gimme some kind code so that i kan understand it better
Posted: Mon Apr 05, 2004 10:04 pm
by Ixplodestuff8
Sorry, but what you seem to be trying to do is more than the scope of a few forum posts, considering I have no idea how you will get the location of the cities, or any locations of any cities, or how to convert latitude and longitude into miles/km, at most I can give you the math part once you have the x/y locations.
Code: Select all
<?php
//$x1 and $y1 is the location of city A
//$x2 and $y2 is the location of city B
//gets the distance
$distance = sqrt ( pow ( ( $x2 - $x1 ), 2 ) + pow ( ( $y2 - $y1 ), 2 ) );
//since there's a high chance it's some big decimal number it's rounded off here
$distance = round ( $distance );
?>
Posted: Mon Apr 05, 2004 10:09 pm
by bugthefixer
well thanx Ixplodestuff
actually i hav predefined distances for railway tracks from one city to another city..n i need to insert these distances in table ..there are more than 600 cities.. at first i thot i shud make a table of 600 rows and 600 cols but this table wud be too big..so i need some easier way..
Posted: Mon Apr 05, 2004 10:26 pm
by Ixplodestuff8
600 cols seems like the only real way to do this, but what I would do is have a list of all the cities in an array, then use this array to create the table stucture, and insert the 600+ rows, then loop through the array and add a zero or a dash for every time a row and col matches. (instead of manually creating the tables and manually inserting all the rows)
Then You could make a webform where you select two city names from a drop down menu(you could use the array from above to populate the dropdown menu), then manually type in the distance, and have it fill both rows that match up for that for you, it'll cut down on the proccess of populating the database