简体   繁体   中英

MySQL Normalization - Structuring a multi-table Real Estate Listing database?

I am trying to convert a paper form to a PHP form that will save property listing information to a database and I'm having trouble wrapping my mind around the best method for doing this. I'm good with PHP, but a bit rusty with database structure and normalization.

I need one table (tblListing) for the property details (listing number, price, address, etc).

But then I need another table (tblPropFeatures) for the property features (Central A/C, Central Heat, Tile, etc)

And yet another (tblLotFeatures) for the lot features (Corner Lot, Cul-de-sac, etc).

The paper form I'm trying to replace has over a hundred checkboxes for property features and lot features, so I want to make sure I separate these so that the db is properly normalized.

But I can't figure out if I need some sort of linking table or if I can just use a regular join.

I'd also like to be able to build the list of checkboxes dynamically from the features that are included in the database table. If a new feature needs to be added in the future an admin can log into phpMyAdmin and add a column to the PropertyFeatures table and the PHP form would be dynamically updated when refreshed and show a new checkbox for the new feature in the db.

Thanks in advance for your help and advice

You need a "listing property features" table that joins listing to propFeatures and a "listing lot features" that joins listing to lotFeatures

These are called many-to-many relationships. You have many property listings that can each have many lot or many property features.

This also achieves your goal of being able to build your checkboxes dynamically. You just need to select all the features from each table and loop through them to make a checkbox. If you joined the properties directly to the features you'd have to duplicate each feature entry.

Just make sure you create each table with a primary key and then index those keys in the joining tables.

Hope that helps! Good luck!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM