mysql多级联动表设计
ringa_lee
ringa_lee 2017-04-17 15:41:28
0
2
636

我设计了一个多级联动的数据库就id. pid name. 三个字段,但是如果街道名字没有,用户可以自己添加街道,比如中山市没有,假设没,用户可以自己写上中山市场。这个数据要怎么关联呢?需要另外建一个表吗

ringa_lee
ringa_lee

ringa_lee

reply all(2)
巴扎黑

You don’t need to use another table as a related table. Isn’t your pid related to the parent id?
If you want to make a related table, you can delete the pid, and then record the relationship in the related table.

Ty80

As mentioned above, pid is the id of the parent address. Users should provide address hierarchical choices when adding, such as the first-level country. After selecting China, the second-level selection province, such as Guangdong Province, The third level selects cities and counties. If there is no Zhongshan City at this time and the user wants to add it, you already know that it is added to Guangdong Province when adding it. Then you should know the ID of the parent address of Zhongshan City and Guangdong Province. Directly Just insert the data and that’s it

insert into table(id,pid,name) select max(id),广东省id,'中山市' from table
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!