title: The way foreign keys work when there are 3 tables dependent on each other
body: <p>I have tables</p>
  
  <pre><code>items
  products
  brands
  </code></pre>
  
  <p>their contents:</p>
  
  <pre><code>products:
  - samsung galaxy s2
  - iphone 5
  
  brands
  - samsung
  - apple
  </code></pre>
  
  <p>the difference between an item and a product is as follows:</p>
  
  <p><strong>product is lets say iPhone.<br>
  item is a certain user's certain iPhone with its own properties like color and purchase price.</strong></p>
  
  <p>the product iPhone has a brand/manufacturer of Apple.</p>
  
  <p>when inserting a new item, I want the database to get the brand from the product the item belongs to, so my foreign key is set up like this:</p>
  
  <pre><code>'db_name`.'products'.`productBrand`
  </code></pre>
  
  <p>I have two brands ATM - Samsung and Apple.</p>
  
  <p>When I try to insert a new item via phpMyAdmin's interface and I get to the itemBrand column, the dropdown field only allows me one option - 1 (Samsung), no matter if I've chosen product 1 or 2 (Samsung Galaxy or iPhone5) at the itemGenericProduct column.</p>
  
  <p>What am I doing wrong?</p>
  
  <p>Here is some more detailed info:</p>
  
  <pre><code>CREATE TABLE IF NOT EXISTS `brands` (
    `brandId` int(11) NOT NULL AUTO_INCREMENT,
    `brandName` varchar(30) NOT NULL,
    `brandLogo` varchar(100) NOT NULL,
    `brandDescription` text NOT NULL,
    PRIMARY KEY (`brandId`)
  ) ENGINE=InnoDB  DEFAULT CHARSET=utf8 AUTO_INCREMENT=3 ;
  
  --
  -- Dumping data for table `brands`
  --
  
  INSERT INTO `brands` (`brandId`, `brandName`, `brandLogo`, `brandDescription`) VALUES
  (1, 'Samsung', '', 'Manufacturer of ...'),
  (2, 'Apple', '', 'American high-tech company ...');
  
  
  --
  -- Table structure for table `items`
  --
  
  CREATE TABLE IF NOT EXISTS `items` (
    `itemId` int(11) NOT NULL AUTO_INCREMENT,
    `generalProductId` int(11) NOT NULL,
    `itemPurchasedPrice` double NOT NULL,
    `itemDateAdded` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
    `itemDescription` text,
    `itemBrand` int(11) NOT NULL,
    `itemBoughtFromPlace` int(11) NOT NULL,
    `itemBoughtFromUser` int(11) NOT NULL,
    `itemConditionNew` tinyint(1) NOT NULL DEFAULT '1',
    `itemBeingSold` tinyint(1) NOT NULL DEFAULT '1',
    `itemSellPrice` double DEFAULT NULL,
    PRIMARY KEY (`itemId`),
    KEY `generalProductId` (`generalProductId`),
    KEY `itemBrand` (`itemBrand`),
    KEY `itemBoughtFromPlace` (`itemBoughtFromPlace`),
    KEY `itemBoughtFromUser` (`itemBoughtFromUser`)
  ) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;
  
  --
  -- Table structure for table `products`
  --
  
  CREATE TABLE IF NOT EXISTS `products` (
    `productId` int(11) NOT NULL AUTO_INCREMENT,
    `productName` varchar(200) NOT NULL,
    `productTimeAdded` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
    `productDescription` text,
    `productBrand` int(11) NOT NULL,
    `productFirstAddedFrom` int(11) NOT NULL,
    `productAvatar` varchar(100) DEFAULT NULL,
    PRIMARY KEY (`productId`),
    KEY `productBrand` (`productBrand`,`productFirstAddedFrom`),
    KEY `productFirstAddedFrom` (`productFirstAddedFrom`)
  ) ENGINE=InnoDB  DEFAULT CHARSET=utf8 AUTO_INCREMENT=5 ;
  
      --
      -- Dumping data for table `products`
      --
  
      INSERT INTO `products` (`productId`, `productName`, `productTimeAdded`, `productDescription`, `productBrand`, `productFirstAddedFrom`, `productAvatar`) VALUES
      (3, 'Samsung Galaxy SII', '2013-10-26 07:46:08', 'The Samsung Galaxy S II is a .....', 1, 1, NULL),
      (4, 'iPhone 5', '2013-10-26 07:46:08', 'The iPhone 5 is a ....', 1, 2, NULL);
  </code></pre>
  
  <p><strong>EDIT:
  the following lines in PRODUCTS table seem strange</strong></p>
  
  <pre><code> KEY `productBrand` (`productBrand`,`productFirstAddedFrom`),
    KEY `productFirstAddedFrom` (`productFirstAddedFrom`)
  </code></pre>
  
  <p>because in the visual layout they look this way:
  <img src="https://i.stack.imgur.com/7t6kk.jpg" alt="enter image description here"></p>