dpl74687 2011-07-07 04:35
浏览 28
已采纳

什么更好? DataBase上的国家,州和城市与否?

I'm developing a website with PHP & MySQL where users can sign up. In the sign up form they need to fill up country, state and city. I want to know if it's a good idea to save it on my database or not. I'm confused because Facebook, google, and others have autocomplete forms where those input tags suggest you country, state and even cities.

  • 写回答

6条回答 默认 最新

  • dongzhan7909 2011-07-07 04:46
    关注

    You should not save all three separately, like country_id, state_id and city_id. The reason being that this is redundant information. A city implicitly belongs to a state belongs to a country. You are not gaining any information by saving them as separate values, and are only introducing the risk of messing up the data (since you could save Japan, Washington, Berlin as a set, which is invalid and inconsistent information).

    You should create an hierarchical tree in your database. Cities have a parent state have a parent country. Then you only need to ask the user for their city and all the other information is implicit. Where you get that data from is a different topic. You can try Google's API, for instance.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(5条)

报告相同问题?

悬赏问题

  • ¥50 切换TabTip键盘的输入法
  • ¥15 关于#网络安全#的问题:求ensp的网络安全,不要步骤要完成版文件
  • ¥15 可否在不同线程中调用封装数据库操作的类
  • ¥15 微带串馈天线阵列每个阵元宽度计算
  • ¥15 keil的map文件中Image component sizes各项意思
  • ¥20 求个正点原子stm32f407开发版的贪吃蛇游戏
  • ¥15 划分vlan后,链路不通了?
  • ¥20 求各位懂行的人,注册表能不能看到usb使用得具体信息,干了什么,传输了什么数据
  • ¥15 Vue3 大型图片数据拖动排序
  • ¥15 Centos / PETGEM