Good, I have the following code where I calculate the number of pieces needed to make a product. I have to fulfill the following formula, item 2 has children so the children depend on the number of this parent.
But I have the following issue when a son of a father has children I need to take the amount of this + the amount of the mother.
I have the following code where I discriminate the recipe. But I can't do the calculation
$cantidad_orden = 10;
$query_orden = "SELECT x.* FROM Details x WHERE id = 1 ORDER BY x.item ASC";
$result = mysqli_query($ConexionMYSQL, $query_orden);
while ($row = mysqli_fetch_assoc($result)) {
$item = $row['item'];
$cantidad_hijo = $row['cantidad'];
$tipo = $row['tipo'];
echo $item . ' >' .$tipo;
echo "<br>";
$level = substr_count($item, '.');
$words = explode(".", $item);
$check_item = $words[0];
if ($actual_item==$check_item) {
echo "Mismo item ".PHP_EOL ;
if ($nivel_item==$level) {
} else {
$nivel_item = $level;
$cantidad_padre = $cantidad_padre * $cantidad_hijo;
echo "Otro nivel :: ".PHP_EOL ;
}
} else {
$actual_item = $check_item;
$cantidad_padre = $cantidad_orden;
echo "Otro item ".PHP_EOL ;
}
echo "<br>";
echo $cantidad_hijo .' * '. $cantidad_padre.' = '. $cantidad_hijo * $cantidad_padre;
echo "<br>";
}
If I run that code I get the following result, sorry for the number of photos and the title.