Hi, I'm having a webpage demo tomorrow, and I'm stuck.
I'm trying to output a recursive menu tree. Fairly simple one.
Parent tree (ws_ProdCat table)
| ID | Category |
1 CPU
2 HDD
3 RAM
Child tre (ws_ProdSubCat table)
|ID | parentID | Sub category |
1 1 Socket 370
2 1 Socket 478
3 1 Socket A
4 2 IDE
5 2 SCSI
6 2 S-ATA
7 3 Socket 370
8 3 Socket 370
9 3 Socket 478
I connect to the DB successfully.
$query = "select ProdCatID, ProdCat from ws_ProdCat";
$mnuParent = mysql_query($query);
$query = "select ParentID, ProdSubCat from ws_ProdSubCat";
$mnuChild = mysql_query($query);
$arrParent = mysql_fetch_array($mnuParent);
$arrChild = mysql_fetch_array($mnuChild);
Pseudocode:
for ($i=0; $i < sizeof($arrParent); $i++)
{
foreach $arrChild
where $arrChild->ParentID == arrParent->ProdCatID
Do
Echo $arrChild['ProdSubCat');
}
I've looked at examples in the PHP docs on FOREACH and how some users have suggested recursive methods using foreach. But I didn't get any wiser.
Is there a simple way of doing this?