Given the form where I select the station (start) and station (end), and it should give all the stops that are in the posmi table, only the station name should be instead of id

There is a stac table with the following cells.

enter image description here

there is a table posmi

enter image description here

And simple form

enter image description here

And when I choose, for example, Tornakalns and Zasulauks, I would get the following:

2 Tornakalns - Zasulauks 3 Zasulauks - Tornakalns 

Here is my under-request:

 select s.stacija, p.id, p.sakstacid, p.beigstacid from posmi as p right join stac as s on p.sakstacid = s.id RIGHT JOIN stac as st ON p.beigstacid=st.id where p.sakstacid in ("'.$_POST['from_place'].'", "'.$_POST['for_place'].'") and p.beigstacid in ("'.$_POST['for_place'].'", "'.$_POST['from_place'].'") 
  • What is given and what to get? For example. given station (?), get a list of neighboring stations? - Sergey
  • Given the form where I choose the station (start) and station (end), and it should give all the stops that are in the posmi table, only the station name should be instead of id - Alexander Reizan
  • one
    Any stops between stations? Stops station too? Here a simple query does not work. Need recursive. It is necessary to think. Look in Google theme recursive cte. And maybe this will not help. After all, the path is unknown in advance, it is necessary to go through all the routes. Download the graph of stops to memory and, according to graph theory, make a path from A to B - Sergey
  • Thanks for the reply) I’m afraid I haven’t really figured out simple queries, it’s too early to deal with recursive ones) - Alexander Reizan
  • Look, I was just looking for a route for one answer and just for MySQL. And there are no normal recursive queries that would greatly simplify the task in MySQL. ru.stackoverflow.com/questions/482044/… - Mike

0