$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; } }