I ask this question in general form because I don't know where to look for this kind of solution.

I need the list of Cities and Villages that will be along the route from from point A (specified by lat,lon) to the point B (also specified by lat,lon). This list should be in correct order from point A to B.

For now I have a database with all Cities, and Villages in Country with lat,lon coordinates for each entry. I don't have connections between those places in this database. Now I'm wondering how to add to this feature to show me the names of the places on the route from point A to point B (or from one place to other)

Can anybody give me some advice how to develop this kind of feature similar to routing. This feature will be developed for the website that is based on PHP and MySQL only.

Several questions come up in my mind. First of all: do you need an exact route between the two places or just an "as the crow flies" straight line? What is the coverage of your app? Whole world or just a single country?

@Breki One Country. No straight line. along the public roads. Straight line with some kilometers tolerancy is simple for me. I see that I need to calculate the route along the public roads. Then in some way analyze this route and get the cities and villages near this route in correct order.

@ChrisH The data is not from OSM. I have database with all the cities and villages from one country but this is not from OSM. I don't have connections between those places in database. I need to get it from some place because without this I can't calculate the route I assume.

Convert the route into something that the database will understand. This is probably a Linestring in either WKT or WKB format.

Use the database's spatial functions to find cities/villages along the route. (Perhaps use the Buffer function to expand the LineString into a Polygon, then the Intersects function to find cities/villages -- note that I haven't checked if those are supported in MySQL).

Sort Cities / Villages so that they are in route-wise order. A simple approximate answer would be to sort them by distance from the starting point, under the assumption that most routes don't backtrack. A more robust approach might be to find the closest city/village to the starting point, then find the point on the route that is closest to that city/village, then repeat using that point as the new starting point and excluding cities that have already been visited.

Items 3 and 4 may not be very practical to do with MySQL because its support for spatial data is very limited. If you could use any free, open source database for this, then PostgreSQL + PostGIS extension would be a much better choice. If you're locked into MySQL, then you'll probably need to do the spatial calculations externally to the database, and I'd look for a PHP wrapper of GEOS or JTS (Java Topology Suite).

I'd also recommend trying the GIS StackExchange site for questions that aren't primarily about working with OSM data.