So the SQL looks a bit like this
Code: Select all
CREATE TABLE `Head` (
`headId` INT UNSIGNED NOT NULL AUTO_INCREMENT,
PRIMARY KEY(`headId`),
`roundness` INT UNSIGNED NOT NULL DEFAULT 0,
`_hairId` INT UNSIGNED NULL
);
CREATE TABLE `Hair` (
`hairId` INT UNSIGNED NOT NULL,
`hexColour` CHAR(6) NOT NULL,
`greasyness` INT UNSIGNED NULL
);Code: Select all
if ($_POST['wantHair']) {
// add a hair record
$hairId = $db->insert_id;
} else {
$hairId = 'null';
}
// create the head record using the $hairId- There is currently no hair on the head and we don't need to add any (SELECT `Head` followed by UPDATE `Head`)
- There is currently no hair on the head and the user wants to add some (SELECT `Head` followed by INSERT `Hair` followed by UPDATE `Head`)
- There is currently hair on the head and the users wants to get rid of it (SELECT `Head` followed by DELETE `Hair` followed by UPDATE `Head`)
- There is currently hair on the head and the user wants to keep it and no doubt update some of properties of the hair (SELECT `Head` followed by UPDATE `Hair` followed by UPDATE `Head`)
Oh this is only with one optional table. What if there are 2 or more! Say I want my head to optionally have a hat.