Search code examples
phpmysqlgeonames

Geonames Cities [postalcodes] table


How i can prevent to receive cities with its subsites and get only the biggest village.

Example:
Currently i get 2 records the first is the main city and the second a neighbor. But i want only the main town.

CH  8280    Kreuzlingen    
CH  8285    Kreuzlingen Ifolor AG <--- needed to be excluded

Regards Sascha


Solution

  • Solution Found ^_^

    You need to detect the first blank space between the town in a foreach loop or similar loop and the $suggestions array contains only the hometowns without its same neighbors.

    Example:

    foreach ($suggestion_cities as $key => $city) {
        if(preg_match('/\s/',$city->city)) {
            continue;
        }
        $suggestions[] = array(
            'value' => $city->city,
            'value_type' => 'city'
        );
    }