php - What's the best way to store Checkbox Values in MySQL Database? -
first, take @ page example: click here
if view 'amenities' section, there 3 sets of checkboxes (unit features, community features , utilities included in rent).
my question is: how can use php make 3 array variables (e.g. $unit_features, $community_features , $utilities_included) store boxes are/are not checked 3 respective fields in table?
more importantly: how pull data out of table in same array format specifics can viewed/edited/deleted?
- note, i've tried countless times having separate fields in table (as tinyints) - gets bulky , isn't elegant @ all...i thought of making object class failed yet again..
you have many-to-many relationship between properties , amenities. model this, need separate table, not variable number of columns.
there 1 table stores properties.
insert property (id, address, square_footage...) values (111, '123 main st', 1234...)
there 1 table stores possible amenities.
insert amenities (id, type, description) values (222, 'unit features', 'air conditioning');
for each amenity property has, insert 1 row table relating these two:
insert property_amenitities (property_id, amenity_id) values (111, 222);
when want know amenities specific property has, select
rows table property's key. when want print out checkboxes amenities, select
amenities
table , left outer join
property_amenities
table. rows null values property_amenities
table boxes unchecked.
related reading. should pick book on relational databases local borders before go out of business :)
Comments
Post a Comment