Reputation: 583
I am trying to create a database where there is a 'n' number of input from html and depending on that number the entry should go in to table column. For instance If a user select option as '4' adult in party with one child.The entry for that in table would go like this
id : 1 | guestid:abc | adult:4 | child:1 |first name : xyz | lastname:xyz | contact: 123 | email: [email protected] |
The problem here is though that i need to save details for every number of guest in this case its 4,the obvious way which i thought was to keep incremanting adult in each row with a value of 1 but that would cause much redundant data in table and very hard to maintain.For instance it would look like this
id : 1 | guestid:abc | adult:1 | child:1 |first name : xyz | lastname:xyz | contact: 123 | email: [email protected] |
id : 2 | guestid:abc | adult:2 | child:1 |first name : zxy | lastname:zxy | contact: 123 | email: [email protected] |
id : 3| guestid:abc | adult:3 | child:1 |first name : lol | lastname:lol | contact: 123 | email: [email protected] |
As it is just not the case it can be any possible number 4,2 5,1 etc.What would be the best way to design a query to address this problem here
Upvotes: 0
Views: 49
Reputation: 1317
You want a master-detail relationship. Where common columns/values are in a Master table and the non-repeating column/values are in a Detail table.
In Master: id, guestid, child, contact, email,
In Detail: id, first name, last name
Also have a look into normalization.
Upvotes: 1