close ad
 
Important WebAssist Announcement
open ad
View Menu

Technical Support Forums

Free, outstanding support from WebAssist and your colleagues

Database structure advice sought

Thread began 8/17/2014 8:57 am by Patrice | Last modified 8/18/2014 8:53 am by Patrice | 796 views | 2 replies

CraigRBeta Tester

I am guessing you are setting up a clothing store, selling mens/womens/unisex? clothing

If this is the case, I think your table structure seems too complicated.

Based on your image, I’m not sure where the unisex fits in, but here is a simple structure, which allows each item to have several sizes available, based on the data in your table.

Have a table for items
Have a table for sizes
Have a table for item sizes

tblitems contains the product information
tblsizes contains all of the size information
tblitemsize is the linking table so you can create a many-many relationship.

On this basis, any item can potentially have any size, but you can use logic in your web pages admin if desired to restrict options, so you cannot associate womens sizes with mens clothing for example.

Eg you could add a M/F field to the sizes table

I added some dummy data to the basic table layout

CREATE TABLE IF NOT EXISTS `tblitems` (
`ItemID` int(11) DEFAULT NULL,
`ItemDescription` varchar(255) DEFAULT NULL
) ENGINE=MyISAM DEFAULT CHARSET=utf8;



INSERT INTO `tblitems` (`ItemID`, `ItemDescription`) VALUES
(1, 'Mens Shirt'),
(2, 'Ladies Trousers'),
(3, 'Ladies Blouse');

CREATE TABLE IF NOT EXISTS `tblsizes` (
`SIzeID` int(11) DEFAULT NULL,
`SizeDescription` varchar(255) DEFAULT NULL,
`Bust/Chest` varchar(255) DEFAULT NULL,
`Waist` varchar(255) DEFAULT NULL,
`HipSeat/Sleeve` varchar(255) DEFAULT NULL,
`Inseam` varchar(255) DEFAULT NULL
) ENGINE=MyISAM DEFAULT CHARSET=utf8;


INSERT INTO `tblsizes` (`SIzeID`, `SizeDescription`, `BustChest`, `Waist`, `HipSeatSleeve`, `Inseam`) VALUES
(1, 'XS 2-4', '30"-33"', '23"-25"', '33"-35"', '30"'),
(2, 'S 4-6', '33"-35"', '25"-27"', '35"-37"', '30.5"'),
(3, 'M 6-8', '35"-37"', '27"-29"', '37"-40"', '31"'),
(4, 'L 10-12', '37"-40"', '29"-32"', '40"-43"', '31.5"'),
(5, 'XL 14-16', '40"-45"', '32"-35"', '43"-46"', '32"'),
(6, 'S Petite', '-', '-', '35"-37"', '28.5"'),
(7, 'S Long', '-', '-', '35"-37"', '32.5"'),
(8, 'M Petite', '-', '-', '37"-40"', '29"'),
(9, 'M Long', '-', '-', '37"-40"', '33"'),
(10, 'L Petite', '-', '-', '40"-43"', '29.5"'),
(11, 'L Long', '-', '-', '40"-43"', '33.5"'),
(12, 'S', '34"-37"', '28"-30"', '32"-33"', '31.5"'),
(13, 'M', '37"-40"', '32"-34"', '33"-34"', '32"'),
(14, 'L', '40"-45"', '24"-36"', '34"-35"', '32.5"'),
(15, 'XL', '45"-49"', '36"-38"', '35"-36"', '33"'),
(16, 'XXL', '49"-53"', '38"-40"', '36"-38"', '33.5"'),
(17, 'M Short', '-', '-', '32"-34"', '30"'),
(18, 'M Long', '-', '-', '32"-34"', '34"'),
(19, 'L Short', '-', '-', '34"-36"', '30.5"'),
(20, 'L Long', '-', '-', '34"-36"', '34.5"'),
(21, 'XL Short', '-', '-', '36"-38"', '31"'),
(22, 'XL Long', '-', '-', '36"-38"', '31.5"');

CREATE TABLE IF NOT EXISTS `tblitemsize` (
`ItemSizeID` int(11) DEFAULT NULL,
`ItemID` int(11) DEFAULT NULL,
`SizeID` int(11) DEFAULT NULL
) ENGINE=MyISAM DEFAULT CHARSET=utf8;


INSERT INTO `tblitemsize` (`ItemSizeID`, `ItemID`, `SizeID`) VALUES
(1, 1, 12),
(2, 1, 13),
(3, 1, 15),
(4, 2, 6),
(5, 2, 7),
(6, 2, 10),
(7, 3, 1),
(8, 3, 2),
(9, 3, 4);



So, to retrieve all of the available sizes for item 1, the mens shirt
SELECT tblitems.ItemID, tblitems.ItemDescription, tblsizes.SizeDescription, tblsizes.BustChest, tblsizes.Waist, tblsizes.HipSeatSleeve, tblsizes.Inseam
FROM tblitems INNER JOIN tblitemsize ON tblitems.ItemID = tblitemsize.ItemID INNER JOIN tblsizes ON tblitemsize.SizeID = tblsizes.SIzeID
WHERE tblitems.ItemID=1;



Hope this helps

Build websites with a little help from your friends

Your friends over here at WebAssist! These Dreamweaver extensions will assist you in building unlimited, custom websites.

Build websites from already-built web applications

These out-of-the-box solutions provide you proven, tested applications that can be up and running now.  Build a store, a gallery, or a web-based email solution.

Want your website pre-built and hosted?

Close Windowclose

Rate your experience or provide feedback on this page

Account or customer service questions?
Please user our contact form.

Need technical support?
Please visit support to ask a question

Content

rating

Layout

rating

Ease of use

rating

security code refresh image

We do not respond to comments submitted from this page directly, but we do read and analyze any feedback and will use it to help make your experience better in the future.

Close Windowclose

We were unable to retrieve the attached file

Close Windowclose

Attach and remove files

add attachmentAdd attachment
Close Windowclose

Enter the URL you would like to link to in your post

Close Windowclose

This is how you use right click RTF editing

Enable right click RTF editing option allows you to add html markup into your tutorial such as images, bulleted lists, files and more...

-- click to close --

Uploading file...