Hi,
I'm accessing a DB and passing all the returned elements into an array, ie. while quering the db I pass all my details like so into an array
while ($myDB->next_record()){
$messagearray[$parent_id][$category_id]["product_id"] = $p_id;
$messagearray[$parent_id][$category_id]["prod_title"] = $prod_title;
$messagearray[$parent_id][$category_id]["prod_summary"] = $prod_summ;
$messagearray[$parent_id][$category_id]["prod_details"] = $prod_body;
}
Now, I have an array of all the parent id's for the products, the individual category id's and then down to the individ prod details etc.
My problem is accessing this array to output my information like so, ie. I want to list items first by Parent ID, then Category's within that parent, then product id's.
ie :
Parent ID = 1
Category= 23
Products id's: 4,5,67,7,32,5
Category = 89
Products id's: 4,5,67,7,32,5
Parent ID = 3
etc etc.
I've tried using a foreach loop but I can only output the parent id and then not the categories within this.
Here is the loop which only outputs those products with parent id the same as category id:
foreach ($messagearray as $key => $details) {
echo '<h4>'.$key.'</h4>';//;
$parent_catname = $allcategories_array[$key]["name"];
echo 'Parent Name='.$parent_catname.'<br>';
foreach ($details as $newKey) {
echo '<B>ID</B> = '.$newKey['id'];
echo ' <B>Title</b>'.$newKey['prod_title'];
echo '<BR><BR>';
}
}
}
Any help welcome.
Thanks,
R.