tags:

views:

108

answers:

3

Hello,

Can anybody describe me the logic that i can use for bus reservation system. I am using MySql free edition. How can i put a facility where closest city name appears automatically to user.

Eg. If user searches bus from cityA to cityB and there are no buses between cityA and cityB. Then automatically, cityC which is closest to cityA and a bus which is there between cityC and cityB should appear?

+2  A: 

I guess you could have DB table with distances between cities and another with router between cities.

When a user inputs a query for a trip from A->B you can check whether you have A-> in table 2, and if not you select the closest city C for which you have C->B.

Mau
Distance between cities? Is this really the approach or are you kidding with me :o? Say, there are 1000's of cities in one country. So will i have to put all records of cities and their respective distance with other cities? Thus making a giant database of approximately 1000 * 1000 records? And then if i add one more city, enter it's relation with rest 1000 cities :d? Is there no way to specify latitude longtitude etc and let the database handle it by itself? Sql Server 2008 provides a geography datatype. I wanted an equivalent of that in MySql.
Ankit Rathod
I don't think he meant that you would store the distance from any city to any city, just the distance between "connected" cities. So if the only way to get from A to C was through B, you would only store A->B and B->C, then use Dijkstra's algorithm as mentioned before to find the distance/route from A->C
Jason Hall
*Lighten up* if you want any useful answers. If this needs solving so badly that you have to snap at everyone whose answers you don't like, perhaps you should ask somewhere else.
DaveE
+3  A: 

This sounds like a case where you can use Dijkstra's algorithm to find the most efficient route.

Also, the database should not matter as it should be abstracted away rather than affecting the logic in your code.

Daenyth
+2  A: 

Now that you have mentioned lat-long (missing in the question description), see this http://www.scribd.com/doc/2569355/Geo-Distance-Search-with-MySQL

gsharma