Online, Association query problems, such as provincial/municipal association query, level-1 province, level-2 city Association query problems, such as provincial/municipal association query, level-1 province, level-2 city. The results are shown in the form of Jinan Qingdao in Shandong province and Nanjing Suzhou in Jiangsu province.
I am checking the form of Jinan, Shandong, Qingdao, Nanjing, Jiangsu, and Suzhou. it is an array. How to write SQL statements for the two-dimensional array?
Reply to discussion (solution)
This is directly related to the way data is organized.
Let's talk about what your data looks like.
This is directly related to the way data is organized.
Let's talk about what your data looks like.
Databases are level-2 associations of provinces and cities.
Can't you give an example?
Different algorithms have different structures.
Can't you give an example?
Different algorithms have different structures.
Province table, and city table
To output this form: array (
"0" => array (
"Province" => "Shandong"
"Belong" => array (
Array ("city" => "Jinan "),
Array ("city" => "Qingdao "),
);
"1" => array (
"Province" => "Jiangsu"
"Belong" => array (
Array ("city" => "Suzhou "),
Array ("city" => "Nanjing "),
);
);
);
Want this form
I know what you want
But you need to know how your database is stored, whether it is a multi-table or a single table, what is the name and encoding?
I know what you want
But you need to know how your database is stored, whether it is a multi-table or a single table, what is the name and encoding?
The database is saved by province and city. province. id = city. pid. the province id is the city's pid. for the two tables, the encoding is utf8.
Create temporary table province (id int, name varchar (10) charset gbk; create temporary table city (id int, pid int, name varchar (10) charset gbk; insert into province values (1, 'Shandong '); insert into city values (1, 1, 'jinan'); insert into city values (2, 1, 'Qingdao '); insert into province values (2, 'Jiangsu '); insert into city values (3, 2, 'Suzhou'); insert into city values (4, 2, 'Nanjing '); select id, 0 as pid, name from provinceunionselect pid, id, name from cityorder by 1, 2
Id pid name 1 0 Shandong 1 1 Jinan 1 2 Qingdao 2 0 Jiangsu 2 3 Suzhou 2 4 Nanjing
It is best to paste the table structure