Not having much luck creating a sub array, partially because I don't fully grasp how keys work.
Here is what I am trying to do:
$sql = "select * from products";
$db->query($sql);
$products = $db->rows();
foreach($products as $key=>$row) {
$sql = "select * from sub_products WHERE productid = " . (int)$row['ID'] . "";
$db->query($sql);
$subproducts = $db->rows();
$products[$key]['subproducts'] = $subproducts;
foreach($products[$key]['subproducts'] as $rr=>$x) {
$sql = "select * from subsubproducts WHERE subproducts = " . (int)$x['ID'] . "";
$db->query($sql);
$subsubproducts = $db->rows();
$products[$key]['subproducts']['subsubproducts'] = $subsubproducts;
}
}
I am not really grasping the concept of keys here and so therefore I am having a hard time understanding how to insert sub-arrays into other sub-arrays.
Currently, the code above, instead of placing the subsubproducts array as an array/item within the subproducts array, it is tagging it on as another item/array. i.e. under subproducts you have:
subproduct1
subproduct2
subsubproducts
Whereas it should be:
subproduct1
---subsubproductslisting
subproduct2
---subsubproductslisting.