php - MySQL relations for country region and town tables -
i trying figure out best method relate country, region , town tables.
on website want user able enter town. optionally country , region, both of required entered or not @ all.
currently tables such
tbl>user has townid (fk)
tbl>town has id(pk) townname regionid(fk default null)
tbl>region has id(pk) regionname countryid(fk not null)
tbl>country has id(pk) countryname
i thought possibly further spit user town relation to:
tbl>user has locationid (fk)
tbl>location has id (pk) townid(fk) regionid(fk) countryid(fk)
but think unnecessary , further complicates issue?
the country database populated. intend build own references of town > region > country relations entered users. if user enters town no region , country entered tbl>town without regionid if there isn't town same name without region id. same town region , country id has been entered user. check there isn't town > region > country relation exists before entering. later on in development of site providing ajax suggestions country/region based upon town entered user.
so questions:
i can envisage pitfalls such duplicate data or data possibly being overwritten. there better way construct tables fit in desired methods?
this might answered prior question: there can reduce php processing of tables. i'd prefer insert 1 php statement think there many caveats @ once.
also users town entry may null , may or may not contain foreign key reference region how best create view takes consideration?
as hosted rather not using mysql functions.
please let me know if need clarification. want right first time before continuing, invaluable.
i don't think reduce code because it's explicit. can change it, won't better.
Comments
Post a Comment