I've a problem that confuses me and can not get solved...
I have 1 for each loop which runs through all products and then inside I have another for each loop for some specific product parameters that I need to combine into one string (string, array or serialized data) and save info in data base.
foreach ($products as $product) {
$parameter1 = $product_parameter1;
foreach ($products_extra_parameters as $product_extra_parameter) {
$parameter2 .= $product_extra_parameter . '|';
}
$insert_data = "INSERT INTO table (parameter1,parameter2) values ('$parameter1','$parameter1')";
if (!mysqli_query($conn, $insert_data)):
fwrite($fh, "Error: " . $insert_data . "\n" . mysqli_error($conn). "\n");
endif;
}
The problem is that with '.=' it adds previous results to the next product (first product have: 'product1_parameter2_value1|product1_parameter2_value' and next one: 'product1_parameter2_value1|product1_parameter2_value|'product2_parameter2_value1|product2_parameter2_value' and so on and on...
I just need to save combined product attributes in 1 table column (using just string combining or can be serialize) for appropriate product and just this product parameters! And I'll have several such parameters that I need to combine in 1 parameter and save in 1 column...
What I'm missing here/doing wrong?