Hi Neil,
Since a start and destination station are involved, if you only need to know all possible stations serviced by direct trains between the two stations this can be derived from the timetable dataset;
http://nrodwiki.rockshore.net/index.php/AtocTimetableFeedFor example, for services from Stafford to Manchester Piccadilly
http://www.railalefan.co.uk/rail/stations.php?dep=STA&arr=MANI already have the timetable feed parsed into a `services` table which includes a `route` column containing a slash separated list of all calling points, for example;
services.origin = "BHM"
services.destination = "LIV"
services.route = "BHM/CSY/WVH/PKG/STA/CRE/RUN/ALE/LIV"
So in stations.php, the route column is queried using a suitable LIKE clause to return all distinct calling point sequences between origin and destination from which the distinct station list can be derived and just needs to be de-duplicated.
As my database also has lat/lon data for all stations ( from
https://data.gov.uk/dataset/naptan ) the list is then sorted by distance from origin (destination always last though!).
Routing of course is not taken into account, continuing the above example, there are no scheduled services between Stafford and Manchester Picadilly that call at both Macclesfield and Wilmslow.
Also consider, if it is relevant to your application, last-train stoppers / positioning services that have calling patterns that are not consistent with the hourly/regular daytime schedule.
Hope this helps!