ok, here scratch that above... same concept... but here is an example of the code output i need from those tables
// Starts with these 2 given variables
$depart = 1;
$arrive = 5;
// generates this from the timetables table
$timetable[0] = array(1, array(1,2,3,4,9));
$timetable[1] = array(2, array(7,3,8,5,6));
$timetable[2] = array(3, array(10,4,2,9,7));
// Runs through w/ the $depart, and returns all routes
$route[0] = array(1,2,9,7);
$route[1] = array(1,2,3,8,5,9);
$route[2] = array(1,2,3,4,2,3,4,9);
$route[3] = array(1,2,3,4,2,9,7);
$route[4] = array(1,2,3,4,9);
Then obvously, $route[1] would be the correct route, not only is it the shorttest, but it is the only one available