Home  >  Q&A  >  body text

mysql多级联动表设计

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

ringa_leeringa_lee2742 days ago660

reply all(2)I'll reply

  • 巴扎黑

    巴扎黑2017-04-17 15:43:28

    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.

    reply
    0
  • PHP中文网

    PHP中文网2017-04-17 15:43:28

    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

    reply
    0
  • Cancelreply