Distance table design
I need to develop a table that will contain the distance between destinations and need some help for that. I'm almost empty now on how to start
here the table shows the distance from the point, A to A, B, C AND D ARE 0, 4, 8, AND 12
respectively, etc.
you need to convert this data into a MySQL table to be managed through the admin panel and used on the client site depending on the destination and destination.
Hello
source to share
If you don't have a "real" date (eg geolocation) you will need to store the data in 2 tables.
First table, locations (so store A, B, C, D there and other relevant location information)
Second table, 3 columns. from_location, to_location, distance. (with the key from / to _location, so it is unique. But always check it the other way around before inserting as you can support A, C and C, A in your table)
This way you can retrieve the correct data from the database easily.
For example getting the distance from A to C ( SELECT distance FROM distance_table WHERE from_location = "A" AND to_location = "C"
)
source to share
So, basically you want a three-column table. Point A, point B, distance
In your program, you can do 2 for a loop to get 2 size table as inserts.
If you want it to be unique then in your code you want to try, if you are looking at B on A now, check if A exists before B before inserting it again. It might be wise to also place some constraint on the table where PointA and PointB must be unique
source to share