$originsql = qq{ SELECT a.stop_reference, b.service_id, distance(PointFromText('POINT($origin)', 27700),east_north), c.route_number FROM bus_stops a, service b, routes c WHERE distance(PointFromText('POINT($origin)', 27700),east_north) < 200 AND a.stop_reference = b.stop_reference AND b.service_id = c.service_id ORDER BY b.service_id, distance(PointFromText('POINT($origin)', 27700),east_north)}; $sth = $dbh->prepare( $originsql ); $sth->execute(); $sth->bind_columns( undef, \$origin_stops, \$origin_service, \$origin_distance, \$origin_route_number); while ($sth->fetch()) { if ($orig_service != $last_service_id) { print "The bus stop located nearest to your Origin area is: ".$origin_stops."
\n"; print "And the bus stop is ".$origin_distance." metres away from your location
\n"; print "This stop serves route number ".$origin_route_number."

\n"; $last_orig_service_id = $origin_service; } } #### $destsql = qq{ SELECT a.stop_reference, b.service_id, distance(PointFromText('POINT($dest)', 27700),east_north), c.route_number FROM bus_stops a, service b, routes c WHERE distance(PointFromText('POINT($dest)', 27700),east_north) < 200 AND a.stop_reference = b.stop_reference AND b.service_id = c.service_id ORDER BY b.service_id, distance(PointFromText('POINT($dest)', 27700),east_north)}; $sth = $dbh->prepare( $destsql ); $sth->execute(); $sth->bind_columns( undef, \$destination_stops, \$destination_service, \$destination_distance, \$destination_route_number); while ($sth->fetch()) { if ($dest_service != $last_service_id) { print "The bus stop located nearest to your Origin area is: ".$destination_stops."
\n"; print "And the bus stop is ".$destination_distance." metres away from your location
\n"; print "This stop serves route number ".$destination_route_number."

\n"; $last_dest_service_id = $destination_service; } }