M
M
Mick-Penny Kwaomaochkrya2015-08-18 23:26:15
PHP
Mick-Penny Kwaomaochkrya, 2015-08-18 23:26:15

How to enter address info?

A typical solution is required for a typical task: enter 3 upper levels of the address: country - region - city (or settlement). HTML + PHP. DB structure? Reference codes of regions, cities where to get (at least for Russia, better - for many countries)?
Thank you!

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
AlikDex, 2015-08-19
@AlikDex

habrahabr.ru/post/204840
or
manually: 1 database of cities ( www.geonames.org/) , three requests.
1) select a country
2) use Ajax to load a request for the regions of the country,
3) repeat the feint with Ajax, but already load the settlements of the selected region.

D
Dmitry Kim, 2015-08-19
@kimono

In general, the database structure is as follows:

CREATE TABLE `points` (
  `id` int(11) NOT NULL AUTO_INCREMENT COMMENT 'ID',
  `parent` int(11) DEFAULT NULL COMMENT 'Родитель',
  `name` varchar(128) NOT NULL COMMENT 'Название',
  PRIMARY KEY (`id`),
  KEY `parent` (`parent`)
) ENGINE=MyISAM AUTO_INCREMENT=0 DEFAULT CHARSET=utf8;

INSERT INTO `points` (`parent` ,`name`) VALUES (NULL, 'Россия');
-- 'Россия': ID = 1
INSERT INTO `points` (`parent` ,`name`) VALUES (1, 'Хабаровский край');
-- 'Хабаровский край': ID = 1234
INSERT INTO `points` (`parent` ,`name`) VALUES (1234, 'Хабаровск');

But for better interoperability, use Nested sets. The base structure is like this:
CREATE TABLE `points` (
  `id` int(11) NOT NULL AUTO_INCREMENT COMMENT 'ID',
  `left_key` int(11) DEFAULT '0' COMMENT 'Левый ключ',
  `right_key` int(11) DEFAULT '0' COMMENT 'Правый ключ',
  `parent` int(11) DEFAULT NULL COMMENT 'Родитель',
  `level` tinyint(1) NOT NULL DEFAULT '0' COMMENT 'Уровень вложенности',
  `name` varchar(128) NOT NULL COMMENT 'Название',
  PRIMARY KEY (`id`),
  KEY `left_key` (`left_key`),
  KEY `right_key` (`right_key`),
  KEY `parent` (`parent`)
) ENGINE=MyISAM AUTO_INCREMENT=0 DEFAULT CHARSET=utf8;

Nested sets provide faster fetching and convenience. Only after any change in the database you will need to run the key distribution procedure. When I wrote my bike, I came across zabolotnev.com/mysql-nested-sets , from there I got some info.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question