The Following Codes are examples I made up to depict my situation.
I have 3 html 'Selects' with multiple options. Each day, users have to select a minimum of one option for each 'Select'.
<html>
<head></head>
<body>
<form id="frm" action="Save.php" method="POST">
<input type="text" id="datepicker" name="datepicker" readonly='true'>
<select id="OptionType1" multiple="multiple">
<option value="1">Option 1</option>
<option value="2">Option 2</option>
<option value="3">Option 3</option>
</select>
<select id="OptionType2" multiple="multiple">
<option value="1">Option 1</option>
<option value="2">Option 2</option>
<option value="3">Option 3</option>
</select>
<select id="OptionType3" multiple="multiple">
<option value="1">Option 1</option>
<option value="2">Option 2</option>
<option value="3">Option 3</option>
</select>
</form>
</body></html>
CREATE TABLE `m` (
`ID` int(11) NOT NULL AUTO_INCREMENT,
`Client ID` int(11) DEFAULT '0',
`Date` date DEFAULT NULL,
`Category` int(11) DEFAULT '0' COMMENT 'categoryA-1,categoryB-2,categoryC-3',
`OptionsType1` int(11) DEFAULT '0',
`OptionsType2` int(11) DEFAULT '0',
`OptionsType3` int(11) DEFAULT '0',
PRIMARY KEY (`ID`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
This DB Structure can only take one OptionType value each.
Client ID,Date,Category are used to make a unique index. The unique index is used for "Insert Into... ON Duplicate Key Update". The reason I used the unique index is so the user can go back and edit their option and mysql will update it based on the unique index.
Due to the Unique Index I cannot make multiple rows with the same Client ID,Date,Category. My only other option is to concatenate my values together in the same row but that could cause performance issues if I decided to look for those values down the line.
Can anyone help me with this dilemma. I need the right structure to save my multiple values and be able to load it back on html and have the user able to update it. Thanks
UPDATE: Two tables are created
CREATE TABLE `m` (
`ID` int(11) NOT NULL AUTO_INCREMENT,
`Client ID` int(11) DEFAULT '0',
`Date` date DEFAULT NULL,
`Category` int(11) DEFAULT '0' COMMENT 'categoryA-1,categoryB-2,categoryC-3',
PRIMARY KEY (`ID`),
UNIQUE KEY `uniq` (`Client ID`,`Date`,`Category`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
CREATE TABLE `c` (
`ID` int(11) NOT NULL AUTO_INCREMENT,
`OptionsType1` int(11) DEFAULT '0',
`OptionsType2` int(11) DEFAULT '0',
`OptionsType3` int(11) DEFAULT '0',
`REF ID` int(11) DEFAULT '0',
PRIMARY KEY (`ID`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
Is there a way to replace existing data (c table) without deleting. Unique index does not exist on c table only primary key but i do not keep track of that when loading html form.
OptionTypecolumns. Use 2 tables and haveOptionTypeand the value in the other table with an id that maps back to themtable.ID,Client ID,Date,Categoryand c table withPrimarykey ID,OptionsType1,OptionsType2,OptionsType3,Reference IDand join m.IDon c.Reference ID? Seems like a good ideainsert/updatequery at that point. If it is an insert that conflicts it is an error no because they should't be able to update multiple times? If I misread though than issue the constraint and update on the second table.