need help on associative table
Moderator: General Moderators
-
bugthefixer
- Forum Contributor
- Posts: 118
- Joined: Mon Mar 22, 2004 2:35 am
need help on associative table
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...
- Ixplodestuff8
- Forum Commoner
- Posts: 60
- Joined: Mon Feb 09, 2004 8:17 pm
- Location: Queens, New York
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.
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.
Last edited by Ixplodestuff8 on Mon Apr 05, 2004 10:26 pm, edited 1 time in total.
-
bugthefixer
- Forum Contributor
- Posts: 118
- Joined: Mon Mar 22, 2004 2:35 am
gimme some kind of code
may be u r right but kan u gimme some kind code so that i kan understand it better
- Ixplodestuff8
- Forum Commoner
- Posts: 60
- Joined: Mon Feb 09, 2004 8:17 pm
- Location: Queens, New York
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 );
?>-
bugthefixer
- Forum Contributor
- Posts: 118
- Joined: Mon Mar 22, 2004 2:35 am
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..
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..
- Ixplodestuff8
- Forum Commoner
- Posts: 60
- Joined: Mon Feb 09, 2004 8:17 pm
- Location: Queens, New York
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
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