I have a table of data "products" and a second table "product_components".
The "products" are made up of any number of "product_components" each of which can also have any number of "product_components" themselves. Products and components are linked using a third table "product_bom".
Costs are stored at the "product_components" level.
I can easily get the price for each "products" line, by adding up its components, and I can repeat the query within itself to look for a second layer of components.
Can anyone suggest how I might infinitely check for another level of components for each component of each component...........etc.?
Thanks,
Euphbasio
Update: This is my basic query for the top level. I could nest a copy of this in the resulting loop and again under that, however this would mean a finite number of possibilities.
SELECT `product_bom`.*, `products_boml`.`product_code` AS `pcode`,`products_boml`.`title` AS `title`, IF(`currency_rates`.`rate`>0,`products_boml`.`cost` * `currency_rates`.`rate`,`products_boml`.`cost`) AS `pcost`,`currency`.`currency` AS `curletters`FROM `product_bom` LEFT JOIN `products` `products_boml` ON `products_boml`.`id`=`product_bom`.`bom_part_id`
LEFT JOIN `products` `products_tlp` ON `products_tlp`.`id`='$product_id'
LEFT JOIN `business_relations` `br_boml_vendor` ON `br_boml_vendor`.`id`=`products_boml`.`vendor_id`
LEFT JOIN `business_relations` `br_tlp_vendor` ON `br_tlp_vendor`.`id`=`products_tlp`.`vendor_id`
LEFT JOIN `currency_rates` ON `currency_rates`.`base_currency_id`=`br_boml_vendor`.`currency` AND `currency_rates`.`exchange_currency_id`=`br_tlp_vendor`.`currency`
LEFT JOIN `currency` ON `currency`.`id`=`br_tlp_vendor`.`currency`
WHERE `product_bom`.`product_id`='$product_id'
ORDER BY `products_boml`.`product_code`
I'm converting for currency also, but that can be ignored.
Thanks.