No need in fact, you just just have to build up a distinct list on the main table of products(where ID's are generated and uniques).
Sommething like :
built up the list :
$q = "SELECT ID, productName FROM Products";
$r = mysql_query($q) or die(mysql_error()."<br /><br />".$q);
and for each item you rebuild is genealogy calling the recursive function :
while($d = mysql_fetch_array($r))
echo "<p class=\"node0\">".$d."</p>";//display node 0
single_genealogy($d, 1);//get and display the filiation following with node 1
what will the recursive function look like?
you have to define this, somewhere before the above :
function single_genealogy($category, $level = 0)
// the sons of the current node = the IDs that are matched with this parentid
$q = "SELECT p.ID, productName FROM Products join ProductCategories USING(ID) WHERE ParentID = ".$category;
$r = mysql_query($q); //or die/mail/echo mysql_error()
while($d = mysql_fetch_row($q))
echo "<p class=\"node".$level."\">".$d."</p>";//displaying current node : $d
//recursive call :
In fact what I call "node".$level (node1 node2 node3 etc....) are CSS classes for <p> (for example with spécifics indent, size)
depending on the level in the tree.
If you hate CSS and its classes, You could also imagine a simple cumulative indent :
with a #define indent = value;
echo "<p style=\"text-indent : ".($level * ident)."\">".$d."</p>";//displaying current node : $d
Well, that's all, I think all will just look like that, no more, , define the function, and then a a first query that list products and their names, and foreach one, we built and display is filiation.
Does that make sense ? 🙂