Related query problems, such as provincial and municipal related queries, first-class provinces, two-tier city. The results are as follows: Jinan, Qingdao, Shandong, Jiangsu Province, Nanjing, Suzhou, this form.
I am now looking for Shandong Jinan, Shandong Qingdao, Jiangsu, Nanjing, Jiangsu Suzhou This form, is an array. Want to find out what kind of two-dimensional array to write SQL
Reply to discussion (solution)
This is directly related to the way data is organized.
Let's talk about what your data is.
This is directly related to the way data is organized.
Let's talk about what your data is.
The database is a two-level association of Provinces and cities.
Can't you give me an example?
Different algorithms for structure are different
Can't you give me an example?
Different algorithms for structure are different
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 you want it this way.
But you need to know how you put it in the library, whether it's a multi-table or a single-table, what the name and code are.
I know you want it this way.
But you need to know how you put it in the library, whether it's a multi-table or a single-table, what the name and code are.
The library is according to the province and the city, province.id = City.pid, the province's ID is the city's PID, the two tables, the code is UTF8
Create temporary table province (id int, name varchar) CharSet gbk;create temporary table city (id int, pid int, name varchar (+) charset Gbk;insert into province values (1, ' Shandong '); insert into city values (1, 1, ' Jinan '); insert INTO city value S (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
ID PID name 1 0 Shandong 1 1 jinan 1 2 Qingdao 2 0 Jiangsu 2 3 Suzhou 2 4
Best to post a table structure