Project Aim :
We are developing bus timing Api
where user will search for buses.
Following are my table structure
I have following tables
buses
id | bus_name
Description of table: Store all buses Names
routes
id | route_name
Description of table: Store All city names
stops
id | stop_name
Description of table: All stop names
stop_orders
id | route_id | stop_id | stop_order
Description of table: here i will assign stops for city and stop_order column help to identify which stop next to each other
bus_timing
id | stop_order_id | bus_id | bus_timing | trip | trip_direction
Description of table: Here i will assign buses for route stops along with time and trip and direction
Output Expecting:
When user search between source to destination with time then Api must return all buses list with time
if direct buses not there then interconnected buses should show
For example if user search between stop_8
to stop_18
with 01:00:00
to 12:00:00
then all buses list with time should show.if direct buses not there to travel between two stops then interconnected link buses list should show
Output what i got is
PHP compare associative array based on condition
Present return result issue is
It will return all buses even though if bus is only travel to stop_8
but not stop_18
.But my result must return only those buses which will travel between two stops i mean it must fall between both stops .
Even i have no idea how to find interconnected buses list
When time range is long then there is chance of same bus will travel(trip and direction) multiple times
Updates
Still looking for answer .Right now given answer has some points so offered bounty
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…