Well, I'm going to try to organize things better, because your explanation was not very clear to me at least.
Let's say we have a products table first:
CREATE TABLE IF NOT EXISTS 'produtos' (
'ID_PRODUTO' int(11) NOT NULL AUTO_INCREMENT,
'DESCRICAO' varchar(255) COLLATE utf8_unicode_ci NOT NULL,
PRIMARY KEY ('ID_PRODUTO')
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
This product has various sizes and sizes. There are some approaches around this, I could have for example a TEXT field in this table of products to store this array in JSON for example, but there is no Array type field in MySQL, this is usually found in NoSQL database, as is the case with MongoDB.
Knowing this we will need to create a new table with the connection of this product with its quantity and sizes. Soon we will have a table products_called_quantities :
CREATE TABLE IF NOT EXISTS 'produtos_tamanhos_quantidades' (
'ID_PRODUTO_TAMANHO_QUANTIDADE' int(11) NOT NULL AUTO_INCREMENT,
'ID_PRODUTO' int(11) NOT NULL,
'TAMANHO' varchar(100) COLLATE utf8_unicode_ci NOT NULL,
'QUANTIDADE' int(11) NOT NULL,
PRIMARY KEY ('ID_PRODUTO_TAMANHO_QUANTIDADE')
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
It's worth remembering that I'm not creating any Foreign Key here, but could easily be added by linking the size and quantity table to the product table.
In this way, when you save the product in the product table, you will then go through your array of quantities and sizes by inserting a line for each size and quantity in the table " products_standards_quantities ". A basic example in PHP would look like this:
<?php
$conecta = mysql_connect("HOST", "LOGIN", "SENHA") or print (mysql_error());
mysql_select_db("BANCO", $conecta) or print(mysql_error());
$sql = "INSERT INTO produtos (DESCRICAO) VALUES ('Caixa de Papelão')";
mysql_query($sql, $conecta);
$idProdutoInserido = mysql_insert_id();
$tamanhosQuantidade = array('15cm' => 30, '30cm' => 50, '45cm' => 20);
foreach($tamanhosQuantidade as $key => $value){
$sql = "INSERT INTO produtos_tamanhos_quantidades (ID_PRODUTO, TAMANHO, QUANTIDADE) VALUES (" . $idProdutoInserido . ", '" . $key . "', $value)";
mysql_query($sql, $conecta);
}
?>
In the above code we connected to the database, we performed the insertion of a product into the table, and then we got the ID that MySQL generated for that product. Then I created an example array with sizes and quantities, ran through the foreach command, performing an insert for each size.