I need to retrieve particular items (Ex: ItemID=1,5,19,36). The problem
is I cannot make it that way that the item is under necessary
categories and subcategories.
"TintedS" wrote in message
news:1137290126.401821.246300@z14g2000cwz.googlegroups.com.. .
> Hi.
>
> my db has
>
> categories(CatID,ParentID,CatName)
> items(ItemID,CatID,ItemName)
>
> I need to retrieve particular items (Ex: ItemID=1,5,19,36). The problem
> is I cannot make it that way that the item is under necessary
perhaps you should try recursion.
a tree_roots table, a subcategories table, and a categories table to hold
strings is what I did.
if a root has no subcategories, nothing goes in the subcategories table.
this code is untested.
include 'database_inc.php'; //sets $link
//-----------this code has not been debugged as of
1/30/2006-------------------
function traverse_tree($level=1,$cat_id) {
global $link;
$qr2=mysql_query("SELECT c.category,sc.subcat_id FROM categories AS
c,subcategories AS sc WHERE c.cat_id=$cat_id AND sc.cat_id=$cat_id ORDER BY
c.category", $link);
//make indenting for categories
$pad=""; for ($i=1; $i<=$level; $i++) {$pad .= " ";}
echo "$pad\[ \n"; //start of category set
while ($rowr2=mysql_fetch_array($qr2)) {
echo $pad . $rowr2['c.category'] . " \n";
traverse_tree($level+1,$rowr2['sc.subcat_id']);
}
echo "$pad\] \n"; //end of category set
}
function traverse_tree_select($level=1,$cat_id,$text) {
//just surround the call to this function with